Deks1948 Posted March 29, 2014 Share Posted March 29, 2014 i'm having hard time thinking out how can i make a PHP dropdown search for a real estate website. So I have made the MYSQL cities and propertyes but i dont know how to make the categories and when you search like a MobilePhone to come another dropdown menu and to select the phone model and to display the results in another page.. the city list <?php // // Database `realestate` // // `realestate`.`cities` $cities = array( array('id' => '1','name' => 'Burgas'), array('id' => '2','name' => 'Lovech'), array('id' => '3','name' => 'Pernik'), array('id' => '4','name' => 'Plovdiv'), array('id' => '5','name' => 'Razgrad'), array('id' => '6','name' => 'Rila'), array('id' => '7','name' => 'Ruse'), array('id' => '8','name' => 'Shumen'), array('id' => '9','name' => 'Sofia'), array('id' => '10','name' => 'Stara Zagora'), array('id' => '11','name' => 'Varna'), array('id' => '12','name' => 'Veliko Tarnovo') ); ?> property type <?php // // Database `realestate` // // `realestate`.`property` $property = array( array('id' => '1','name' => 'Huizen in de omgeving','property_type' => '0','property_subtype' => '0'), array('id' => '2','name' => 'Appartementen','property_type' => '0','property_subtype' => '0'), array('id' => '3','name' => 'Huizen','property_type' => '0','property_subtype' => '0'), array('id' => '4','name' => 'Bouwgrond','property_type' => '0','property_subtype' => '0'), array('id' => '5','name' => 'Commercieel','property_type' => '0','property_subtype' => '0'), array('id' => '6','name' => 'Te Huur','property_type' => '0','property_subtype' => '0') ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/287384-multiply-search-box/ Share on other sites More sharing options...
ginerjm Posted March 29, 2014 Share Posted March 29, 2014 This seems to imply multiple dropdown boxes. Is that what you were asking about in your subject line? So - since it is to be more than one dropdown, let's start out simple. First - create the first dropdown and send it out. Then when the user clicks on a choice and submits the form, take the selected item and create the next dropdown and sent it all back to the user. Repeat for each successive dropdown that you need. PS - you can do this with ajax to make it slicker, but for now you might want to just go back and forth. Quote Link to comment https://forums.phpfreaks.com/topic/287384-multiply-search-box/#findComment-1474394 Share on other sites More sharing options...
Deks1948 Posted March 30, 2014 Author Share Posted March 30, 2014 <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('realestate'); $query="SELECT * FROM country"; $result=mysql_query($query); ?> <script language="javascript" type="text/javascript"> function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getState(countryId) { var strURL="findState.php?country="+countryId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('statediv').innerHTML=req.responseText; document.getElementById('citydiv').innerHTML='<select name="city">'+ '<option>Select City</option>'+ '</select>'; } else { alert("Problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function getCity(countryId,stateId) { var strURL="findCity.php?country="+countryId+"&state="+stateId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('citydiv').innerHTML=req.responseText; } else { alert("Problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> <form method="post" action="" name="form1"> <center> <table width="45%" cellspacing="0" cellpadding="0"> <tr> <td width="75">City</td> <td width="50">:</td> <td width="150"><select name="country" onChange="getState(this.value)"> <option value="">Select City</option> <?php while ($row=mysql_fetch_array($result)) { ?> <option value=<?php echo $row['id']?>><?php echo $row['city']?></option> <?php } ?> </select></td> </tr> <tr style=""> <td>Type</td> <td width="50">:</td> <td ><div id="citydiv"><select name="city"> <option>Select Type</option> </select></div></td> </tr> </table> </center> </form> <?php $countryId=intval($_GET['country']); $stateId=intval($_GET['type']); $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('realestate'); $query="SELECT id,city FROM city WHERE countryid='$countryId' AND stateid='$stateId'"; $result=mysql_query($query); ?> <select name="city"> <option>Select City</option> <?php while($row=mysql_fetch_array($result)) { ?> <option value><?php echo $row['type']?></option> <?php } ?> </select> like that? Quote Link to comment https://forums.phpfreaks.com/topic/287384-multiply-search-box/#findComment-1474421 Share on other sites More sharing options...
ginerjm Posted March 30, 2014 Share Posted March 30, 2014 Perhaps. IMHO - your code is too confusing to follow. You have JS, HTML and PHP all just running on in a single path, making it hard to understand. If you think you've got it, congratulations. Quote Link to comment https://forums.phpfreaks.com/topic/287384-multiply-search-box/#findComment-1474427 Share on other sites More sharing options...
Deks1948 Posted March 31, 2014 Author Share Posted March 31, 2014 Is there any tutorial that I could find to make it more simple?? Quote Link to comment https://forums.phpfreaks.com/topic/287384-multiply-search-box/#findComment-1474472 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.