Forum Moderators: coopster
The drop down is a city, state combo. The checkboxes are populated from an array and correspond with 1 column in the database. The radio groups are also populated from arrays and are stored in a total of two columns.
If someone selects no checkboxes, it should mean the user doesn't care if the results have any of the amenities. If they select them all, that means they require all of the amenities.
For the first radio group, it represents closing hours. For example, if they want a place open until midnight, everything open midnight and later should show up.
The last radio group is simply one of three choices.
I'm not sure if I have setup the form and the table in the most efficient way and I really have no clue how to setup the search results (I'm very new to the use of arrays).
I'm attempting to develop in DWMX04.
Here's the head of my search form:
<?php require_once('Connections/latenite.php');?>
<?php
mysql_select_db($database_latenite, $latenite);
$query_rsCity = "SELECT * FROM cities ORDER BY city ASC";
$rsCity = mysql_query($query_rsCity, $latenite) or die(mysql_error());
$row_rsCity = mysql_fetch_assoc($rsCity);
$totalRows_rsCity = mysql_num_rows($rsCity);
?>
<?php
$amenities = array("Full Bar","Beer and/or Wine","Late Night Happy Hour","Live Music","Outdoor Dining");
$hours = array("10","11","12","1","2","All Night");
$smoking = array("Smoking Allowed","Non-Smoking Section","No Smoking");
?>
Here's the form itself:
<form name="form1" id="form1" method="post" action="searchresults.php">
<table width="0%" border="1" bordercolor="#FF0000" bgcolor="#0000FF">
<tr>
<th scope="row">City:</th>
<td><select name="cityID" id="cityID">
<?php
do {
?>
<option value="<?php echo $row_rsCity['cityID']?>"><?php echo $row_rsCity['city'] . ", " . $row_rsCity['state']?></option>
<?php
} while ($row_rsCity = mysql_fetch_assoc($rsCity));
$rows = mysql_num_rows($rsCity);
if($rows > 0) {
mysql_data_seek($rsCity, 0);
$row_rsCity = mysql_fetch_assoc($rsCity);
}
?>
</select>
</td>
</tr>
<tr>
<th scope="row">Amenities:</th>
<td>
<?php
$arrayCount = count($amenities);
for ( $count = 0 ; $count < $arrayCount ; $count++ ) {
echo "<input type='checkbox' name='$amenities[$count]' value='$count' />" . "$amenities[$count]" . "<br />";
}
?>
</td>
</tr>
<tr>
<th scope="row">Serve food until: </th>
<td>
<p><?php
$arrayCount = count($hours);
for ( $count = 0 ; $count < $arrayCount ; $count++ ) {
echo "<label><input type='radio' name='rg1' value='$count' />" . "$hours[$count]" . "</label><br />";
}
?></p>
</td>
</tr>
<tr>
<th scope="row">Smoking:</th>
<td>
<p><?php
$arrayCount = count($smoking);
for ( $count = 0 ; $count < $arrayCount ; $count++ ) {
echo "<label><input type='radio' name='rg2' value='$count' />" . "$smoking[$count]" . "</label><br />";
}
?></p>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="Submit" value="Search" />
<input type="reset" name="Submit2" value="Reset" /></th>
</tr>
</table>
</form>
Any help would be greatly appreciated. Thanks everybody!
You're creating checkboxes with name='$amenities[$count]'
The should look like this to make the form return an array:
Amenities:
<input type="checkbox" name="amenities[]" value=1> amenity 1
<input type="checkbox" name="amenities[]" value=2> amenity 2
<input type="checkbox" name="amenities[]" value=3> amenity 3
Identical name, with [].
In the PHP-script use print_r($_POST); to see what gets sent to the server. If for example the second and third boxes are ticked:
Array
(
[amenities] => Array
(
[0] => 2
[1] => 3
))
So there is an array called $_POST['amenities'] waiting for further processing.
The select box will return one value (if a choice has been made), and so will each group of radio buttons.
I hope this gets you going.