greencoin Posted June 28, 2007 Share Posted June 28, 2007 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 Link to comment https://forums.phpfreaks.com/topic/57552-solved-multiple-checkbox-query-using-text-as-values-not-numbers/ Share on other sites More sharing options...
HuggieBear Posted June 28, 2007 Share Posted June 28, 2007 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 Link to comment https://forums.phpfreaks.com/topic/57552-solved-multiple-checkbox-query-using-text-as-values-not-numbers/#findComment-284815 Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 So as it stands I misinterpreted the code? This will pass each text value to the query? Thanks ~Rich Link to comment https://forums.phpfreaks.com/topic/57552-solved-multiple-checkbox-query-using-text-as-values-not-numbers/#findComment-284820 Share on other sites More sharing options...
HuggieBear Posted June 28, 2007 Share Posted June 28, 2007 That's correct. Regards Rich Link to comment https://forums.phpfreaks.com/topic/57552-solved-multiple-checkbox-query-using-text-as-values-not-numbers/#findComment-284822 Share on other sites More sharing options...
greencoin Posted June 28, 2007 Author Share Posted June 28, 2007 THANKS! This sucker is closed.... ~Rich Link to comment https://forums.phpfreaks.com/topic/57552-solved-multiple-checkbox-query-using-text-as-values-not-numbers/#findComment-284828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.