lightnb
08-07-2006, 06:17 AM
My script querys the database, and uses a while loop to generate a check box for each unique manufacturer.
when you select one of the boxes and submit the form, it displays all the items made by that manufacturer.
When you select more than one checkbox, it doesn't work.
the variable "$checkbox_name" only contains one value. What do i need to do to make more than one checkbox at a time work?
Live example: http://www.rahlentertainment.com/db_results.php
My script:
if ( $go_button == "go!" ) // check to see if the user has submited the filter form
{ // If so, figure out what the user wants, display the form again, and display the filtered results:
// crteate the query string based on user input
if(isset($make_checkbox))
{
$where_string = " WHERE make = '" .$make_checkbox. "'";
}
// show the filter form again:
echo "this form has been submited";
echo $make_array;
echo "<form action='" .$PHP_SELF. "' method='post'>";
// Begin the dynamically generated select box
$manu_sql = "SELECT distinct make FROM " .$lighting_fixtures_table_name;
$manu_result = mysql_query($manu_sql);
While ( $manu_row = mysql_fetch_array ( $manu_result ) )
{
echo $manu_row[make] . ': <input name="make_checkbox" type="checkbox" id="make_checkbox" value="' . $manu_row[make] . '"><br/>';
}
// END SELECT BOX
//Submit Button
echo "<input type='submit' name='go_button' value='go!'/>";
// END SUBMIT BUTTON
echo "</form>"; // END FORM
// display the filtered results
$sql = "SELECT distinct make as mnf
FROM $lighting_fixtures_table_name";
if(isset($where_string))
{
$sql .= $where_string;
}
else{
$sql .= " ORDER BY mnf";
}
//$result = mysql_query($sql); // use this line live, and the one below for debugging
$result = mysql_query($sql) or die("Query failed: $sql - " . mysql_error()); //use this line for debugging or the one above for live environment
while ( $row = mysql_fetch_array( $result ) )
{
echo "<fieldset><legend>$row[mnf]</legend><table align='center'><tr>";
$sub_sql = "SELECT make, model, type
FROM $lighting_fixtures_table_name
WHERE make = '".$row[mnf]."'
ORDER BY model";
//echo $sub_sql; //Show the query for debuggin purposes (othewise comment out this line)
$sub_result = mysql_query($sub_sql);
$line_counter = 1; //initialize the line counter
while ( $sub_row = mysql_fetch_array( $sub_result ) )
{
if ($line_counter == 5)
{
echo "</tr><tr>";
$line_counter = 1;
}else
{
$line_counter = $line_counter + 1;
}
// This code is the individual result box
echo "<td>";
echo '<table width="116" border="0"><tr><td width="110" height="114" background="http://www.rahlentertainment.com/lxc/graphics/database_icon.jpg"><div align="center">';
echo $sub_row[type];
echo "</div></td></tr>";
echo '<tr><td><div align="center"><b>' . $sub_row[make] . "</b></div></td></tr>";
echo '<tr><td><div align="center">' . $sub_row[model] . "</div></td></tr></table>";
echo "</td>";
// END RESULT BOX
}
echo "</tr></table></fieldset><br><br>";
}
when you select one of the boxes and submit the form, it displays all the items made by that manufacturer.
When you select more than one checkbox, it doesn't work.
the variable "$checkbox_name" only contains one value. What do i need to do to make more than one checkbox at a time work?
Live example: http://www.rahlentertainment.com/db_results.php
My script:
if ( $go_button == "go!" ) // check to see if the user has submited the filter form
{ // If so, figure out what the user wants, display the form again, and display the filtered results:
// crteate the query string based on user input
if(isset($make_checkbox))
{
$where_string = " WHERE make = '" .$make_checkbox. "'";
}
// show the filter form again:
echo "this form has been submited";
echo $make_array;
echo "<form action='" .$PHP_SELF. "' method='post'>";
// Begin the dynamically generated select box
$manu_sql = "SELECT distinct make FROM " .$lighting_fixtures_table_name;
$manu_result = mysql_query($manu_sql);
While ( $manu_row = mysql_fetch_array ( $manu_result ) )
{
echo $manu_row[make] . ': <input name="make_checkbox" type="checkbox" id="make_checkbox" value="' . $manu_row[make] . '"><br/>';
}
// END SELECT BOX
//Submit Button
echo "<input type='submit' name='go_button' value='go!'/>";
// END SUBMIT BUTTON
echo "</form>"; // END FORM
// display the filtered results
$sql = "SELECT distinct make as mnf
FROM $lighting_fixtures_table_name";
if(isset($where_string))
{
$sql .= $where_string;
}
else{
$sql .= " ORDER BY mnf";
}
//$result = mysql_query($sql); // use this line live, and the one below for debugging
$result = mysql_query($sql) or die("Query failed: $sql - " . mysql_error()); //use this line for debugging or the one above for live environment
while ( $row = mysql_fetch_array( $result ) )
{
echo "<fieldset><legend>$row[mnf]</legend><table align='center'><tr>";
$sub_sql = "SELECT make, model, type
FROM $lighting_fixtures_table_name
WHERE make = '".$row[mnf]."'
ORDER BY model";
//echo $sub_sql; //Show the query for debuggin purposes (othewise comment out this line)
$sub_result = mysql_query($sub_sql);
$line_counter = 1; //initialize the line counter
while ( $sub_row = mysql_fetch_array( $sub_result ) )
{
if ($line_counter == 5)
{
echo "</tr><tr>";
$line_counter = 1;
}else
{
$line_counter = $line_counter + 1;
}
// This code is the individual result box
echo "<td>";
echo '<table width="116" border="0"><tr><td width="110" height="114" background="http://www.rahlentertainment.com/lxc/graphics/database_icon.jpg"><div align="center">';
echo $sub_row[type];
echo "</div></td></tr>";
echo '<tr><td><div align="center"><b>' . $sub_row[make] . "</b></div></td></tr>";
echo '<tr><td><div align="center">' . $sub_row[model] . "</div></td></tr></table>";
echo "</td>";
// END RESULT BOX
}
echo "</tr></table></fieldset><br><br>";
}