spectsteve7 Posted January 3, 2007 Share Posted January 3, 2007 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. Quote Link to comment Share on other sites More sharing options...
craygo Posted January 3, 2007 Share Posted January 3, 2007 You can make the drop downs whole numbers then use sql to get the results[code]<?phpecho "<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 widthQuery[code]$sql = "SELECT * FROM table WHERE width <='".$_POST['width']."' AND height <= '".$_POST['height']."'";[/code]Ray Quote Link to comment Share on other sites More sharing options...
spectsteve7 Posted January 3, 2007 Author Share Posted January 3, 2007 I can't use whole numbers because the data in the database are not whole numbers i.e. 2.25, .75 etc. I want to drill down using whole numbers stating display widths that are less than 1" and heights less than 2" Quote Link to comment Share on other sites More sharing options...
craygo Posted January 3, 2007 Share Posted January 3, 2007 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 Quote Link to comment Share on other sites More sharing options...
spectsteve7 Posted January 3, 2007 Author Share Posted January 3, 2007 I have them in as int. No I don't need the last bit of functionality. But now that I have that code into the page, how do I make it take that information and display the results on the results page on submition? Quote Link to comment Share on other sites More sharing options...
craygo Posted January 3, 2007 Share Posted January 3, 2007 [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] Quote Link to comment Share on other sites More sharing options...
marcus Posted January 3, 2007 Share Posted January 3, 2007 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] Quote Link to comment Share on other sites More sharing options...
spectsteve7 Posted January 3, 2007 Author Share Posted January 3, 2007 Craygo do I put this on the page with the form? Or on the results page? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.