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
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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[code]$sql = "SELECT * FROM table WHERE width <='".$_POST['width']."' AND height <= '".$_POST['height']."'";
$res = mysql_query($sql) or die (mysql_error());
while($r = mysql_fetch_assoc($res)){
  echo $r['field1']."
}
?>[/code]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.