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

Search with multiple select

Thread began 1/25/2017 7:11 am by georgina_barrett_187762 | Last modified 2/01/2017 12:18 pm by Ray Borduin | 38 views | 4 replies |

georgina_barrett_187762

Search with multiple select

I have a form with 2 fields one of which is a multiple select:
<form id="form1" name="form1" method="get" action="wagesList.php"><table>
<tr>
<th>
Select Week:</th>
<td><select name="Week[]" multiple="multiple" id="Week">
<?php
while(!$week->atEnd()) { //dyn select
?>
<option value="<?php echo($week->getColumnVal("Week")); ?>"><?php echo($week->getColumnVal("Week")); ?></option>
<?php
$week->moveNext();
} //dyn select
$week->moveFirst();
?>
</select></td>
<td>&nbsp;</td>
</tr>
<tr>
<th>Travel Expert:</th>
<td><select name="expert" id="expert">
<?php
while(!$expert->atEnd()) { //dyn select
?>
<option value="<?php echo($expert->getColumnVal("TravelExpert")); ?>"><?php echo($expert->getColumnVal("TravelExpert")); ?></option>
<?php
$expert->moveNext();
} //dyn select
$expert->moveFirst();
?>
</select></td>
<td><input name="submit" type="submit" class="managerbutton" id="submit" value="Submit" /></td>
</tr>


</table>
</form>

I am trying to search the database for records that match (both fields are varchar). The expert column is optional, but the Week column has to have a value. This is my code:
<?php
$commission = new WA_MySQLi_RS("commission",$horizon_i,0);
$commission->setQuery("SELECT Commissions.*, Request.TravelExpert FROM Request JOIN Commissions ON Request.ID=Commissions.RequestID WHERE Request.TravelExpert LIKE ? AND Commissions.Week=?");
$commission->bindParam("c", "".$_GET['expert'] ."", "-1"); //colname
$commission->bindParam("s", "".$_GET['Week'] ."", "-1"); //colname1
$commission->execute();
?>
If there is one value submited for 'Week' it works but if multiple are it doesn't. How do I get it to search multiple values?

Sign in to reply to this post

Ray BorduinWebAssist

Try:

php:
<?php

$commission 
= new WA_MySQLi_RS("commission",$horizon_i,0);
$commission->setQuery("SELECT Commissions.*, Request.TravelExpert FROM Request JOIN Commissions ON Request.ID=Commissions.RequestID WHERE Request.TravelExpert LIKE ? AND Commissions.Week IN ?");
$commission->bindParam("c""".$_GET['expert'] ."""-1"); //colname
$commission->bindParam("sl""".implode(",",$_GET['Week']) ."""-1"); //colname1
$commission->execute();
?>
Sign in to reply to this post

georgina_barrett_187762

That works perfectly if there are more that one values in the week field eg.
?Week[]=117&Week[]=217&expert=&submit=Submit
but if there is only one eg. ?Week[]=117&expert=&submit=Submit
it gives me this error:

SELECT Client.ID AS ClientID, Client.Title, Client.FirstName, Client.Surname FROM Client JOIN Request ON Client.ID=Request.ClientID JOIN Commissions ON Request.ID=Commissions.RequestID WHERE Request.TravelExpert LIKE ? AND Commissions.Week IN ?

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1

Sign in to reply to this post

Ray BorduinWebAssist

Try adding the parenthasis like:

$commission->setQuery("SELECT Commissions.*, Request.TravelExpert FROM Request JOIN Commissions ON Request.ID=Commissions.RequestID WHERE Request.TravelExpert LIKE ? AND Commissions.Week IN (?)");

Sign in to reply to this post

georgina_barrett_187762

Perfect thanks

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