UQ13A Posted April 1, 2010 Share Posted April 1, 2010 Hi. I have a from with two Drop Down Menu's (Make and Model). If you select a Car Make from the Make list and Select ANY from the Car Model list. i want it to show all the car models for that make. (Sorry if its hard to understand) here is my form code <form action="search.php" method="GET" name="search"><br /> <select name="make" size="1" class="textbox" id="make"> <option selected="selected" value="">Select Manufacturer</option> <option value="HONDA">HONDA</option> <option value="TOYOTA">TOYOTA</option> </select> <br /><br /> <select name="model" size="1" class="textbox" id="model"> <option selected="selected" value="">Select Model</option></select> <option value="ANY">ANY</option> <option value="CIVIC">HONDA CIVIC</option> <option value="JAZZ">HONDA JAZZ</option> <option value="COROLLA">TOYOTA COROLLA</option> <option value="PRIUS">TOYOTA PRIUS</option> <br /> <br /><br /> <select name="price" class="textbox"> <option value="" selected>Max Price</option> <option value="1000">Up to £1,000</option> <option value="2000">Up to £2,000</option> <option value="3000">Up to £3,000</option> <option value="4000">Up to £4,000</option> </select> <br /><br /> <input type="submit" name="Submit" id="Submit" class="button" value="Find Car >>"> <br> </form> here is my php code <?php if(isset($_GET['Submit'])) { if($_GET['make'] == "") { echo "Error! you need to select a Car Manufacturer"; exit; } else { // Create the variables again. $form_make = $_GET['make']; $form_model = $_GET['model']; $make = mysql_real_escape_string($form_make); $model = mysql_real_escape_string($form_model); // IF THE VALUE OF THE THE 2ND DROP DOWN MENU IS ANY THEN I WANT TO IGNORE AND `Model`='$model' $query = ("SELECT * FROM `car` WHERE `Make`='$make' AND `Model`='$model' ORDER BY `Price` ASC"); $result = mysql_query($query); $numResults = mysql_num_rows($result); if ($numResults == 0) { echo "<u><div align=\"center\">Your search for $make $model ($type) returned $numResults results</div></u>"; exit; } else { // data from query, react accordingly echo "<u><div align=\"center\">Your search for $make $model ($type) returned $numResults results</div></u>"; $i=1; while($row = mysql_fetch_array($result)) { $image = $row['image']; $price = $row['Price']; $town = $row['Town']; $mileage = $row['Mileage']; $colour = $row['colour']; $fuel = $row['fuel']; $transmission = $row['transmission']; $comments = $row['Comments']; $owner = $row['owner']; $id = $row['id']; $Left = $row['days_left']; $comments1 = substr($comments ,0,100); $price1 = round($price, 2); $mileage1 = round($mileage, 2); ?> <br /><br /> <?php print "<div style=\"background-color:#FFFFFF;\" class=\"asAdvertContainer\"> <img src=\"$image\" width=\"125\" height=\"125\" border=\"2.5\"/> <span class=\"carText\"><span align=\"right\"><strong>Make $make | Model $model | Price £$price1 | Location $town <br /> Owner $owner</strong></span><br /> <ul> <li><strong>$mileage1 miles</strong> | <strong>$transmission</strong></li> <li><strong>$colour</strong> <strong>| $fuel</strong></li> </ul>Days Remaining $Left</span> <div align=\"center\"> <textarea name=\"textarea\" cols=\"45\" rows=\"5\" readonly=\"readonly\" class=\"comments\" id=\"textarea\">$comments1</textarea> <br /><a href=\"#\" onclick=\"OpenBrWindow('viewcar.php?carid=$id','','width=600,height=630')\">View full description</a> </div> </div> <br />"; $i++; } } } else { echo "Submit button not pressed"; } Link to comment https://forums.phpfreaks.com/topic/197284-using-valueany-in-php/ Share on other sites More sharing options...
trq Posted April 2, 2010 Share Posted April 2, 2010 if ($model == 'ANY') { $query = "SELECT * FROM car WHERE Make = '$make' ORDER BY Price ASC"; } else { $query = "SELECT * FROM car WHERE Make = '$make' AND Model = '$model' ORDER BY Price ASC"; } Link to comment https://forums.phpfreaks.com/topic/197284-using-valueany-in-php/#findComment-1035634 Share on other sites More sharing options...
UQ13A Posted April 2, 2010 Author Share Posted April 2, 2010 if ($model == 'ANY') { $query = "SELECT * FROM car WHERE Make = '$make' ORDER BY Price ASC"; } else { $query = "SELECT * FROM car WHERE Make = '$make' AND Model = '$model' ORDER BY Price ASC"; } Thanks i'll give it a try Link to comment https://forums.phpfreaks.com/topic/197284-using-valueany-in-php/#findComment-1035849 Share on other sites More sharing options...
UQ13A Posted April 2, 2010 Author Share Posted April 2, 2010 thanks it worked perfectly. Link to comment https://forums.phpfreaks.com/topic/197284-using-valueany-in-php/#findComment-1035916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.