Jump to content

Recommended Posts

Is PHP used to create this type is feature? I already have a MYSQL table set up, how difficult is it to create this sort of feature?

 

On this image, where it says 'filter your results' if a user clicks 'Detached Houses' then only detached houses will be displayed. if a user clicks 'Semi-detached' then only semi detached houses will be shown.

 

Whats the technical term for this type of feature, and can you point me towards any tutorials etc, would really appreciate it. thank you!

post-130660-13482403468117_thumb.png

Thanks mate. Is this the right way to do it? but how would I get the php to execute once a user selects 'Detached Houses'

 


<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div id="filter"><p class="houses" style="font-family:helvetica;color:#0155a1;font-size:14px;background:url(cutouts/forsale/filter.jpg) no-repeat;"><b><u>Houses</u></b>
					<br />
					<span class="dh"><b><u>Detached Houses</u></b></span><?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Get a specific result from the "example" table
$result = mysql_query("SELECT * FROM example
WHERE name='Sandy Smith'") or die(mysql_error());  

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
// Print out the contents of each row into a table 
echo $row['name']." - ".$row['age'];
?>
					<br />
					<span class="dh"><b><u>Semi-detached houses</u></b></span>
					<br />
					<span class="dh"><b><u>Terraced houses</u></b></span>
					<br />
					<br />
					<b><u>Flats / Apartments</u></b>

</p></div></td>

You can make this as simple/straightforward as:

 

function get_detached_houses($mysql) {
  $sql = 'SELECT * FROM real_estate WHERE type_id = 5'; // 5 = Detached House
  $rows = mysql_fetch_all($sql, $mysql, MYSQL_ASSOC);
  return $rows;
}

 

You can check what the user asked for by creating URL's like:

 

estate.php?type=semi-detached
estate.php?type=detached
..

 

In your code you would use the type to display the correct properties:

 

$mysql = mysql_connect(/*...*/);
if (get('type') === 'detached') {
  $estate = get_detached_houses($mysql);
} else if (get('type') === 'semi-detached') {
  // ..
} else {
  $estate = get_houses();
}

 

mysql_fetch_all and get are custom functions:

 

function get($name, $default = null) {
  return array_key_exists($name, $_GET) ? $_GET[$name] : $default;
}

// executes a query and returns a result set
function mysql_fetch_all($sql, $mysql, $mode = MYSQL_BOTH) {
  $rows = array();
  $res = mysql_query($sql, $mysql);
  if ($res && mysql_num_rows($res)) {
    while ($row = mysql_fetch_array($res, $mode)) {
        $rows[] = $row;
    }
  }
  return $rows;
}

Thanks so much for your reply and lengthy explanations. Have I placed it in the right place?, and I just need to change my credentials and other parts of the code such as table name etc.


<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div id="filter"><p class="houses" style="font-family:helvetica;color:#0155a1;font-size:14px;background:url(cutouts/forsale/filter.jpg) no-repeat;"><b><u>Houses</u></b>
					<br />
	<a href="www.mumtazproperties.hostei.com/show_houses.php?type=semi-detached"><span class="dh"><b><u>Detached Houses</u></b></span></a>
<?php
function get_detached_houses($mysql) {
  $sql = 'SELECT * FROM real_estate WHERE type_id = 5'; // 5 = Detached House
  $rows = mysql_fetch_all($sql, $mysql, MYSQL_ASSOC);
  return $rows;
}	

$mysql = mysql_connect(/*...*/);
if (get('type') === 'detached') {
  $estate = get_detached_houses($mysql);
} else if (get('type') === 'semi-detached') {
  // ..
} else {
  $estate = get_houses();
}

function get($name, $default = null) {
  return array_key_exists($name, $_GET) ? $_GET[$name] : $default;
}

// executes a query and returns a result set
function mysql_fetch_all($sql, $mysql, $mode = MYSQL_BOTH) {
  $rows = array();
  $res = mysql_query($sql, $mysql);
  if ($res && mysql_num_rows($res)) {
    while ($row = mysql_fetch_array($res, $mode)) {
        $rows[] = $row;
    }
  }
  return $rows;
}					
?>						

Will the PHP code work for all the different url's e.g. for "detached" "terraced houses" etc once they are set too.

Ignore previous post on php code, thanks.


<div id="main">

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div id="filter"><p class="houses" style="font-family:helvetica;color:#0155a1;font-size:14px;background:url(cutouts/forsale/filter.jpg) no-repeat;"><b><u>Houses</u></b>
					<br />
	<a href="www.mumtazproperties.hostei.com/show_houses.php?type=semi-detached"><span class="dh"><b><u>Detached Houses</u></b></span></a>

					<br />
					<span class="dh"><b><u>Semi-detached houses</u></b></span>
					<br />
					<span class="dh"><b><u>Terraced houses</u></b></span>
					<br />
					<br />
					<b><u>Flats / Apartments</u></b>

</p></div></td>
<td><div id="info1"><a href="#"><img src="cutouts/forsale/pinfo1.jpg" alt=""/></a></div></td>
</tr>
</table>

<div id="info2"><a href="#"><img src="cutouts/forsale/pinfo2.jpg" alt=""/></a></div>
<div id="info3"><a href="#"><img src="cutouts/forsale/pinfo3.jpg" alt=""/></a></div>
<div id="info4"><a href="#"><img src="cutouts/forsale/pinfo4.jpg" alt=""/></a></div>


<?php
function get_detached_houses($mysql) {
  $sql = 'SELECT * FROM real_estate WHERE type_id = 5'; // 5 = Detached House
  $rows = mysql_fetch_all($sql, $mysql, MYSQL_ASSOC);
  return $rows;
}	

$mysql = mysql_connect(/*...*/);
if (get('type') === 'detached') {
  $estate = get_detached_houses($mysql);
} else if (get('type') === 'semi-detached') {
  // ..
} else {
  $estate = get_houses();
}

function get($name, $default = null) {
  return array_key_exists($name, $_GET) ? $_GET[$name] : $default;
}

// executes a query and returns a result set
function mysql_fetch_all($sql, $mysql, $mode = MYSQL_BOTH) {
  $rows = array();
  $res = mysql_query($sql, $mysql);
  if ($res && mysql_num_rows($res)) {
    while ($row = mysql_fetch_array($res, $mode)) {
        $rows[] = $row;
    }
  }
  return $rows;
}					
?>							
</div>

The code I provided will only work for the type=detached, you will have to write the other functions to handle semi-detached, etc... If you do not feel comfortable writing PHP then either: 1) go out and buy a book and read until you feel comfortable with the language or 2) pay someone to do it for you (or teach you, having someone to ask questions directly is often easier).

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.