David S Posted December 17, 2008 Share Posted December 17, 2008 Hi Everybody! My name is David, I have been using PHP for a long time but only recently I got serious with it and started working on bigger projects, involving the use of big SQL databases. Right now I'm involved in a charitable project, www.vsc.org.uk , but I'm having a problem. On the homepage, all the affiliated retailers are usually shown. To achieve that I used this code, to take them from our cp (corporate partners) table and display them on the page: ====================================================================== <?php $self = $_SERVER['PHP_SELF']; { $ctg = @$_GET['c'] ; list($cata, $catb, $catc, $catd, $cate) = explode(" ", $ctg); $query = mysql_query("SELECT * FROM cp ORDER by cp"); while ($row = mysql_fetch_array($query)) ====================================================================== Now, I'd like to create a series of category links on top of the page that, when clicked, look through the cat and subcat columns in my table and show only the suitable affiliate businesses. ======================================================================= <?php $rs = @$_GET['r'] ; list($var1, $var2, $var3, $var4, $var5) = explode(" ", $rs); $query = mysql_query("SELECT * FROM cp WHERE cat LIKE '%$var1%' "); ?> <a href='http://www.vsc.org.uk/index.php?r=Books Magazines'> Books and Magazines</a> <a href='http://www.vsc.org.uk/index.php'> Food and Wine</a> <a href='http://www.vsc.org.uk/index.php'> Business and Finance</a> <a href='http://www.vsc.org.uk/index.php'> Fashion</a> <a href='http://www.vsc.org.uk/index.php'> Holidays</a> <a href='http://www.vsc.org.uk/index.php'> Home and Garden</a> <a href='http://www.vsc.org.uk/index.php'> Entertainment</a> <a href='http://www.vsc.org.uk/index.php'> Computer and Technology</a> <a href='http://www.vsc.org.uk/index.php'> Electrical</a> <a href='http://www.vsc.org.uk/index.php'> Music</a> ====================================================================== For example, after clicking on the links "Books and Magazines" the homepage, instead of showing everything from 123-Reg to WHSmith would show only Waterstones, Pickabook and the other retailers that in the cat or subcat columns are describes as "Books" or "Magazines". When I tested the above code, clicking on the Books and Magazines link, the page was still returning the list of all the affiliate businesses. Any help is much appreciated, thank you! D Quote Link to comment https://forums.phpfreaks.com/topic/137326-sql-link-to-return-only-selected-results/ 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.