close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Search function using multiple checkboxes

Thread began 3/15/2012 3:53 pm by eric284736 | Last modified 3/21/2012 12:05 pm by Jason Byrnes | 4784 views | 10 replies |

eric284736

Search function using multiple checkboxes

Hi,

I want to setup a search function where each search variable will have chechboxes and the user could select one or more checkboxes for each varaible.

Example:
1. Country - France (checkbox) Italy (checkbox) Any(checkbox)
2. Region - Paris(checkbox) Corse(checkbox) Sicily(checkbox) Any(checkbox)
3. Search For - Rental(checkbox) Sale(checkbox) Any(checkbox)
4. Property Type - Home(checkbox) Apartment(checkbox) Any(checkbox)

For the Any checkbox I would want it to return any or all of the records under that variable.
I am just not sure what that value would be to return "any" unspecified record for that search variable.

Can this be done with the Search function?

Thx!
Eric

Sign in to reply to this post

Jason ByrnesWebAssist

yes, this can be done using the data assist search wizard and modifying the search form after it is created.

in the data assist search wizard, add the criteria for each of the columns to use a checkbox, and use the keyword search type.


after the form is created, you will need to add the additional checkboxes for the additional choices.


for example, the from will add the country checkbox as:

<input type="checkbox" name="country" value="country" />


you will need to change that to:
France: <input type="checkbox" name="country[]" value="france" />
Italy:<input type="checkbox" name="country[]" value="Italy" />
Any: <input type="checkbox" name="country[]" value="" />

same for the other column, change the name to include "[]" at the end and set the value for the any option to be blank.

then add the following code at line 1 of the results page:

php:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")     {
    foreach(
$_POST as $key => $val) {
        if(
is_array($_POST[$key])) $_POST[$key] = implode(" "$_POST[$key]);
    }
}
?>
Sign in to reply to this post

eric284736

Excellent!! Thanks Jason!

Sign in to reply to this post

eric284736

Hi Jason,

Okay I have a search form in place and a results page. Here is the Results code:

<?php
if($_SERVER["REQUEST_METHOD"] == "POST") {
foreach($_POST as $key => $val) {
if(is_array($_POST[$key])) $_POST[$key] = implode(" ", $_POST[$key]);
}
}
?>
<?php require_once('Connections/connBLUR.php'); ?>
<?php
//WA Database Search Include
require_once("WADbSearch/HelperPHP.php");
?>
<?php
//WA Database Search (Copyright 2005, WebAssist.com)
//Recordset: rsProp;
//Searchpage: 0test.php;
//Form: form1;
$WADbSearch1_DefaultWhere = "";
if (!session_id()) session_start();
if ((isset($_POST["WADbSearch1"])) && ($_POST["WADbSearch1"] != "")) {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//keyword array declarations
$KeyArr1 = array("Country");

//comparison list additions
$WADbSearch1->keywordComparison($KeyArr1,"".$row_rsProp['Country'] ."","AND","=","%20AND%20","%20OR%20","%22","%22",0);

//save the query in a session variable
if (1 == 1) {
$_SESSION["WADbSearch1_resultsTEST"]=$WADbSearch1->whereClause;
}
}
else {
$WADbSearch1 = new FilterDef;
$WADbSearch1->initializeQueryBuilder("MYSQL","1");
//get the filter definition from a session variable
if (1 == 1) {
if (isset($_SESSION["WADbSearch1_resultsTEST"]) && $_SESSION["WADbSearch1_resultsTEST"] != "") {
$WADbSearch1->whereClause = $_SESSION["WADbSearch1_resultsTEST"];
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
else {
$WADbSearch1->whereClause = $WADbSearch1_DefaultWhere;
}
}
$WADbSearch1->whereClause = str_replace("\\''", "''", $WADbSearch1->whereClause);
$WADbSearch1whereClause = '';
?>

Here is the search form:

<form name="form1" action="resultsTEST.php" method="post">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td width="37" align="right"><label for="Country">Select</label></td>
<td width="200"><input type="checkbox" name="Country[]" value="" />
Any
<input type="checkbox" name="Country[]" value="France" />
France
<input type="checkbox" name="Country[]" value="Italy" />
Italy</td>
</tr>
<tr>
<td align="center" colspan="2"><p>
<input type="submit" name="WADbSearch1" value="Submit" />
</p>
<p>test </p></td>
</tr>
</table>
</form>

What I am not sure about on the search parameter is what the VALUE should be after the Type.

Thx
Eric

Sign in to reply to this post

Jason ByrnesWebAssist

for the value, click the lightning bolt icon and select the country form element.

Sign in to reply to this post

info22862

Can this be done using multiple tables.

I have been attempting to create a similar function.
Basically search for a business profile based on selected check boxes/Radio buttons and drop down lists. However, in my case I have the data in distinct tables.

IE: One table holds the company contact data, another holds the courses they offer.

I want to find all matching companies to the search query, then display each company using repeat record set. The issue I run into, is when trying to display the company I can only display one course they offer, I am not able to select multiple rows from the courses table that match.

I don't expect the pro's like Jason to solve this for me, however if you could enlighten me if this is even possible it would be a great help. I have read that WA is not able to work with multiple tables using DataAssist.

If there is a PHP / MySQL expert who would like to take this on as a side project, educate me and solve the search issue, I would love to outsource it to you.

Thanks in advance - Jerry

Sign in to reply to this post

Jason ByrnesWebAssist

you need to edit the recordset so that it uses a join query to return related data from both tables.

you don't go into to much detail on how the relationship of the 2 tables is created, so i can give an example of the query, but you can find more details on join queries here:

sql_join.asp

Sign in to reply to this post

info22862

Thank you Jason, I'm no MySQL pro for sure, this is my basic structure.

Each Table has a clientid associated with it to help with joins.

states.clientid (states offering services in - multiple rows)
clients.clientid (client contact info - single row)
languages.clientid (languages spoken- multiple rows)
courses.clientid (courses offered- multiple rows)

Select *
where
(formstate=states.statesid and states.clientid=clientsid)
and formlanguages=languages.languagesid
and formcourses=courses.courseid

Results page:
client company
course1
course2
course3
Language 1
language 2
language 3

Repeat recordset to display all matching results.

--------
I don't expect you to crack this nut for me, but perhaps this additional detail will clarify things. I will read up on joins.

Thanks again - Jerry

Sign in to reply to this post

eric284736

Hi Jason,

I did that but it list the 3 checkboxes as country[].

Here are the pages searchtest.php
and if you select France or Italy it shows all the countries.

Let me go back a couple of steps and ask this: When I run the search wizard should I use the single checkbox form element OR the multiple select or checkboxes form element?

thx
Eric

Sign in to reply to this post

eric284736

Jason, here are the zipped test pages.

thx
Eric

Attached Files
New folder.zip
Sign in to reply to this post
loading

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...