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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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']) . "'"; } Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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'] Quote Link to comment 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 Quote Link to comment 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.