List box, query to filter records based on multiple selections
Posted by:
s16m05
Date: March 16, 2005 05:21AM
I can't figure out a query to get multiple selections from a list box to filter records in mysql. Below are sample files of my attempt. Any suggestions? Thanks.
================= form.php =================
<form action="results.php?search=true" method="get" name="form" target="_self" id="form">
<p>
<select name="fruits[]" size="5" multiple>
<option value="apples">Apples</option>
<option value="oranges">Oranges</option>
<option value="pears">Pears</option>
<option value="grapes">Grapes</option>
<option value="mangos">Mangos</option>
</select>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
============================================
================= results.php =================
<?php
$foo = $_GET['fruits'];
if (count($foo) > 0) {
for ($i=0;$i<count($foo);$i++) {
echo "<li>$foo[$i] \n";
mysql_select_db($database_conn, $conn);
$query_Recordset1 = sprintf("SELECT * FROM test WHERE name LIKE '%%%s%%'", $foo[$i]);
$Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
}
}
?>
<html><head></head><body>
<table width="200" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>testID</td>
<td>name</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['testID']; ?></td>
<td><?php echo $row_Recordset1['name']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
</body>
</html>
<?php
?>
============================================
Subject
Written By
Posted
List box, query to filter records based on multiple selections
March 16, 2005 05:21AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.