Jump to content

Multiple Drop Down Query Help Needed


spectsteve7

Recommended Posts

Hi everyone,

I'm trying to select sizes (height and width) from two different form drop down menus then (press submit) to have those selections query a database and then display on a seperate page. I need the height and width dropdowns to query based on less than 1" less than 2" and less than 3". I've made drynamic dropdowns before but never with less than amounts. I have only done single dropdowns with exact urls; i.e. <option value="../details.php?id=443">1-1/8” x 2-1/4”</option>

Hopefully someone can understand and help me out with this.
Link to comment
https://forums.phpfreaks.com/topic/32746-multiple-drop-down-query-help-needed/
Share on other sites

You can make the drop downs whole numbers then use sql to get the results

[code]<?php
echo "<select name=width>";
$widths = array(1,2,3);
foreach($widths as $wvalue){
  echo "<option value=$wvalue>$wvalue</option>";
}
echo "</select>";

echo "<select name=height>";
$heights = array(1,2,3);
foreach($height as $hvalue){
  echo "<option value=$hvalue>$hvalue</option>";
}
echo "</select>";
?>[/code]
do the same for your width

Query
[code]$sql = "SELECT * FROM table WHERE width <='".$_POST['width']."' AND height <= '".$_POST['height']."'";[/code]

Ray
What type did you make the field that holds the numbers, int, float, text??? It shouldn't matter if you use whole numbers or not. If you stored the data in the table correctly, 2.25 is less than 3 no matter which way you slice it. If you stored the data as a varchar or text then you got a problem. Now you will have to use php to convert strings to numbers and such.

Also one other question, are you looking for widths and heights between numbers like ledd than three but greater than 2??

Ray
Well the best to make a drop down is like:

[code]
<?php
$sql = "SELECT * FROM table";
$res = mysql_query($sql);
echo "Width: <select name=width>\n";
while($row = mysql_fetch_assoc($res)){
echo "<option value=$row[width]>$row[width] Inches</option>\n";
}
echo "</select>";
echo "Height: <select name=height>\n";
while($row = mysql_fetch_assoc($res)){
echo "<option value=$row[height]>$row[height] Inches</option>\n";
}
echo "</select>";
?>
[/code]

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.