usman07 Posted April 27, 2012 Share Posted April 27, 2012 I want to create a feature as you see nn 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. Any help is really appreciated, thank you. <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> Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/ Share on other sites More sharing options...
Jessica Posted April 27, 2012 Share Posted April 27, 2012 How many topics have you created about this now? Make the text a link, and in the link add a parameter of what you want to search on. It should look like: http://mysite.com/show_houses.php?type=semi-detached Then on your page you'll check if $_GET['type'] is set and has value, and then create your MySQL query to use that. You have to try it before we can help you fix it. Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341185 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 Im sorry I don't mean to misuse the forums. Thanks for that information, really appreciate it. i will try it. Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341186 Share on other sites More sharing options...
usman07 Posted April 27, 2012 Author Share Posted April 27, 2012 Is this looking ok so far? <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> <?php // Make a MySQL Connection mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") 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> One thing u mentioned that im not sure about is 'Then on your page you'll check if $_GET['type'] is set and has value, and then create your MySQL query to use that.' I have limited knowledge with PHP code i'm afraid, but do i need to set a GET type in the php code? Thank You Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341191 Share on other sites More sharing options...
Psycho Posted April 27, 2012 Share Posted April 27, 2012 One thing u mentioned that im not sure about is 'Then on your page you'll check if $_GET['type'] is set and has value, and then create your MySQL query to use that.' I have limited knowledge with PHP code i'm afraid, but do i need to set a GET type in the php code? Values passed on the URL are available in the global $_GET array. So, if the user access a page using http://mysite.com/page.php?foo=bar&this=that Then when that script runs the $_GET array will look like this array( 'foo' => 'bar', 'this' = 'that' ) So, to expand on what jesirose suggested, you would do something like this: $query = "SELECT * FROM example"; if(isset($_GET['type'])) { $query .= " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'"; } Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341195 Share on other sites More sharing options...
usman07 Posted April 28, 2012 Author Share Posted April 28, 2012 Is this the correct way to do this? <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=detached"><span class="dh"><b><u>Detached Houses</u></b></span></a> <?php // Make a MySQL Connection mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") 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()); $query = "SELECT * FROM example"; if(isset($_GET['type'])) { $query .= " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'"; } // 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> where it says 'example' in the php code, is that where I put the name of my table in MYSQL? Basically what i want it to do is when a user clicks on "detached houses", all the detached house will be displayed from the database. Thank you for your help, much appreciated. Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341332 Share on other sites More sharing options...
usman07 Posted April 28, 2012 Author Share Posted April 28, 2012 I desperately need some help, any help would be hugely appreciated. Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341353 Share on other sites More sharing options...
Zephni Posted April 28, 2012 Share Posted April 28, 2012 <?php $query = mysql_query("SELECT * FROM something WHERE name='someone'"); $result = mysql_fetch_array($query); var_dump($result); ?> Get the result of the query as an array with mysql_fetch_array(); Then access the items with $result['id'] or $result['surname'] Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341374 Share on other sites More sharing options...
usman07 Posted April 28, 2012 Author Share Posted April 28, 2012 Thanks for your reply Zephni, Where abouts would I placed that code in within my previous post of PHP coding? Thanks Link to comment https://forums.phpfreaks.com/topic/261723-php-filtering-results/#findComment-1341382 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.