Jump to content

[SOLVED] Multiple Checkbox Query using text as values not numbers


greencoin

Recommended Posts

so I've been looking to create a query based on multiple checkbox results (select results from multiple cities) and the only examples I've found so far use numbers as the values like the one below;

Page1

<?php
<form action="query.php" method="post" name="myform">
<tr>
<td><select name="name1[]" multiple>
<option value="value1">Value1</option>
<option value="value2">Value2</option>
<option value="value3">Value3</option>
?>

Page2

<?php
mysql_connect("host", "username", "password") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());

$name1 = $_POST['name1'];
for($name1array=0; $name1array < sizeof($name1); $name1array++)
{
if($name1array < (sizeof($name1)-1)) { $name1_cond = " OR "; }
else { $name1_cond = ""; }
$name1q = $name1q."`name1` LIKE
'".$name1[$name1array]."'$name1_cond";
}

$name1q = "($name1q)";
$query = "SELECT * FROM `table` WHERE $name1q LIMIT 0,30";
?>

 

The problem I'm having is converting the FOR loop into something other than numeric. I'm using the actual city name as the value as it is relevant in the way the MySQL tables are setup. I'm sure it can be done but how? HELP!!! ~Rich

I prefer a while() loop, but what you have should work fine.  The for() loop isn't looking at the values of the items to determine how many times to loop, it's looking at a count of how many items are in the array (by using size_of(), the same as count()).

 

Regards

Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.