close ad
 
Important WebAssist Announcement
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 4:11 am by georgina_barrett_187762 | Last modified 9/07/2017 8:39 am by Ray Borduin | 1857 views | 6 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
Did this help? Tips are appreciated...

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
Did this help? Tips are appreciated...

georgina_barrett_187762

Perfect thanks

Sign in to reply to this post

georgina_barrett_187762

I have a new issue with this. I now need to do the same search:
$wagespaid = new WA_MySQLi_RS("wagespaid",$horizon_i,1);
$wagespaid->setQuery("SELECT SUM(Amount) AS sAmount FROM WagesPaid WHERE WagesPaid.Weeks IN (?)");
$wagespaid->bindParam("sl", "".implode(",",$_GET['Week']) ."", "-1");
$wagespaid->execute();

However the WagesPaid.Weeks field in the database is a comma separated field with multiple week numbers. So I have multiple week numbers in the url to search and multiple weeks (separated by commas) in the database to search on. Is this possible?

Sign in to reply to this post

Ray BorduinWebAssist

There is a built in search library in the code, but we don't have it exposed through the extension. That is probably the cleanest solution.

A quick fix would be to write some code to loop through it like:

php:
<?php

$wagespaid 
= new WA_MySQLi_RS("wagespaid",$horizon_i,1);
$wagespaid->setQuery("SELECT SUM(Amount) AS sAmount FROM WagesPaid WHERE 1=0");
for (
$x=0; isset($_GET['Week']) && $x<sizeof($_GET['Week']); $x++) {
  
$wagespaid->Statement $wagespaid->Statement " OR Concat(',',WagesPaid.Weeks,',') LIKE '%,".intval($_GET['Week'][$x]).",%'";
}
$wagespaid->bindParam("sl""".implode(",",) ."""-1");
$wagespaid->execute();
?>
Sign in to reply to this post
Did this help? Tips are appreciated...

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