I've cut and pasted from tutorials and forum posts to come up with the following code. Kinda like the way Frankenstein was put together (a little bit from here and a little bit from there).
My goal has been user input using a checkbox to choose up to 5 cities, along with a dropdown list for nights of the week, then use the form output for the table query. The code works, but the query portion seems awkward. Let's say someone chooses Phoenix and Tucson for the cities & Monday -- If I understand my code correctly, it searches the table for 'Phoenix' & 'Monday' the first time through the loop and then searches the table for 'Tucson' & 'Monday' the second time through the loop. What I think I need is for a single search where it queries ('Phoenix' OR 'Tucson') AND 'Monday'.
How can this be done? If someone could clean this mess up or show me a better way it would be awesome.
//connection
if (!isset($_POST['submit']))
{
echo '
<form action="" method="POST">
please select the cities to search in:<br>
<input type="checkbox" name="checkboxes[]" value="Chandler">Chandler<br>
<input type="checkbox" name="checkboxes[]" value="Gilbert">Gilbert<br>
<input type="checkbox" name="checkboxes[]" value="Mesa">Mesa<br>
<input type="checkbox" name="checkboxes[]" value="Tempe">Tempe<br>
<input type="checkbox" name="checkboxes[]" value="Scottsdale">Scottsdale<br>
<select name="day">
<option>Choose one</option>
<option value="1">Mon</option>
<option value="2">Tue</option>
<option value="3">Wed</option>
<option value="4">Thu</option>
<option value="5">Fri</option>
<option value="6">Sat</option>
<option value="7">Sun</option>
</select>
<input type="submit" name="submit" value="submit">
</form>
';
}
else
{
if (isset($_POST['checkboxes']))
{ $day = $_POST['day'];
echo 'you checked the following boxes:<br><br>';
foreach ($_POST['checkboxes'] as $value)
{
echo $value,$day . '<br>';
$result = mysql_query( "SELECT * FROM karaoke WHERE city='$value' and daycode LIKE '%$day%' ORDER BY venue",$db )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "<table width=70% border=1>\n";
while ($get_info = mysql_fetch_row($result))
{
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
$counter += 1;
}
print "</table>\n";
mysql_close($link);
}
print "There are $counter karaoke sites that match your search.<P>";
}
else
{
echo 'you did not check any boxes';
}
}