Jump to content

Recommended Posts

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')
);

?>

Link to comment
https://forums.phpfreaks.com/topic/287384-multiply-search-box/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/287384-multiply-search-box/#findComment-1474394
Share on other sites

<?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?

Link to comment
https://forums.phpfreaks.com/topic/287384-multiply-search-box/#findComment-1474421
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.