usman07 Posted April 27, 2012 Share Posted April 27, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/ Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 I'm not sure there is a technical term. You just adjust your database query to select the data the user asks for. Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341104 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 Do you have any examples of this or tutorials on how to do this?thanks Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341108 Share on other sites More sharing options...
Jessica Posted April 27, 2012 Share Posted April 27, 2012 Some people might call that "filtering". Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341109 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 Thanks, would u know of any tutorials on how to create this sort of feature? Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341111 Share on other sites More sharing options...
litebearer Posted April 27, 2012 Share Posted April 27, 2012 http://www.tizag.com/mysqlTutorial/mysqlwhere.php Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341121 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341132 Share on other sites More sharing options...
ignace Posted April 27, 2012 Share Posted April 27, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341194 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341200 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341204 Share on other sites More sharing options...
xyph Posted April 27, 2012 Share Posted April 27, 2012 You have to program that functionality in manually, using the same methods that were done for you for detached. Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341207 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 Sorry I don't understand? program it manually? I thought the PHP code goes in the same page, which I will change to a .php file? what method was done for detached? thanks Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341209 Share on other sites More sharing options...
ignace Posted April 28, 2012 Share Posted April 28, 2012 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). Quote Link to comment https://forums.phpfreaks.com/topic/261709-what-is-the-technical-term-used-for-this-feature/#findComment-1341310 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.