close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

using a checkboxes as filter with mysqli query builder

Thread began 5/07/2015 2:58 pm by Paul | Last modified 5/08/2015 2:27 pm by Ray Borduin | 318 views | 3 replies |

Paul

using a checkboxes as filter with mysqli query builder

I used the webassist mysqli query-builder and i probably i did something wrong and need some help.
I have a recordset and 1x input textbox and 4x checkboxes which act as search + filter.

The input textbox filter works, good.... however
the checkboxes seem to respond but i get strange random results

How do i correctly set a filter for every check box?


<b>Here is a simplified version of what my recordset looks like</b>
------------------------------------------------------------------------------------
SELECT tablename.*
FROM tablename
WHERE tablename.country = WAQB_Param1 AND tablename.company = WAQB_Param2 AND tablename.company = WAQB_Param3 AND tablename.company = WAQB_Param4 AND tablename.company = WAQB_Param5
ORDER BY tablename.company ASC
-----------------------------------------------------------------------------------


<b>Here is simplified version of what my PHP code looks like</b>
------------------------------------------------------------------------------------
$filterData = new WA_MySQLi_RS("filterData",$datasheet,0);
$filterData->setQuery("SELECT tablename * FROM tablename WHERE tablename.country = ? AND tablename.company = ? AND tablename.company = ? AND tablename.company = ? AND tablename.company = ? ORDER BY vrzndw_datasheet.col_company ASC");
$filterData->bindParam("s", "".(isset($_POST['searchInput'])?$_POST['searchInput']:"") ."", "-1"); //WAQB_Param1
$filterData->bindParam("s", "".(isset($_POST['filter1'])?$_POST['filter1']:"") ."", "-1"); //WAQB_Param2
$filterData->bindParam("s", "".(isset($_POST['filter2'])?$_POST['filter2']:"") ."", "-1"); //WAQB_Param3
$filterData->bindParam("s", "".(isset($_POST['filter3'])?$_POST['filter3']:"") ."", "-1"); //WAQB_Param4
$filterData->bindParam("s", "".(isset($_POST['filter4'])?$_POST['filter4']:"") ."", "-1"); //WAQB_Param5
$filterData->execute();
------------------------------------------------------------------------------------


<b>This is how the html form looks like</b>
------------------------------------------------------------------------------------
<form id="form1" name="form1" method="post" action="">
<p>
<label for="searchInput"></label>Which the country?
<input name="searchInput" type="text" id="searchInput" />
<input type="submit" name="btnSearch" id="btnSearch" value="Compare" />
</p>
<p>
<label><input type="checkbox" name="filter1" value="A" id="filter1" />Select A</label>
<label><input type="checkbox" name="filter2" value="B" id="filter2" />Select B</label>
<label><input type="checkbox" name="filter3" value="C" id="filter3" />Select C</label>
<label><input type="checkbox" name="filter4" value="D" id="filter4" />Select D</label>
</form>
------------------------------------------------------------------------------------


Is this correct?

Sign in to reply to this post

Paul

I have removed a couple of variables and only created one checkbox groupname.
This seems to work better, however i can only select "1" checkbox at the time.

How to setup multiple checkboxes with querybuilder?

$filterData = new WA_MySQLi_RS("filterData",$datasheet,0);
$filterData->setQuery("SELECT tablename.* FROM tablename WHERE tablename.country = ? AND tablename.company = ? ORDER BY tablename.company ASC");
$filterData->bindParam("s", "".(isset($_POST['searchInput'])?$_POST['searchInput']:"") ."", "-1"); //WAQB_Param1
$filterData->bindParam("s", "".(isset($_POST['filter1'])?$_POST['filter1']:"") ."", "-1"); //WAQB_Param2
$filterData->execute();

Sign in to reply to this post

Ray BorduinWebAssist

How do you want the checkboxes to work? When you check more than one would it return more results or less?

I think the problem was probably with your initial query. I'm guessing it should have been something like:

"SELECT tablename * FROM tablename WHERE tablename.country = ? AND (tablename.company = ? OR tablename.company = ? OR tablename.company = ? OR tablename.company = ?) ORDER BY vrzndw_datasheet.col_company ASC"

otherwise as soon as you leave one checkbox unchecked the query would return no results.

Sign in to reply to this post

Paul

Thanks it worked!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...