Pages: [1]   Go Down
Author Topic: SQL: link to return only selected results  (Read 1436 times)
David S
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 2


« on: December 16, 2008, 04:26:13 PM »

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[/url]
<a href='http://www.vsc.org.uk/index.php'> Food and Wine[/url]
<a href='http://www.vsc.org.uk/index.php'> Business and Finance[/url]
<a href='http://www.vsc.org.uk/index.php'> Fashion[/url]
<a href='http://www.vsc.org.uk/index.php'> Holidays[/url]
<a href='http://www.vsc.org.uk/index.php'> Home and Garden[/url]
<a href='http://www.vsc.org.uk/index.php'> Entertainment[/url]
<a href='http://www.vsc.org.uk/index.php'> Computer and Technology[/url]
<a href='http://www.vsc.org.uk/index.php'> Electrical[/url]
<a href='http://www.vsc.org.uk/index.php'> Music[/url]

======================================================================


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
Report to moderator   Logged

PhPHelper
Full Member
Hero Member
****

Karma: +50/-0
Offline Offline

Posts: 179



WWW
« Reply #1 on: December 17, 2008, 02:45:14 AM »

why are you exploding it if it only contains books when they are clicked on?

Code:
$rs = @$_GET['r'] ;
list($var1, $var2, $var3, $var4, $var5) = explode(" ", $rs);
Report to moderator   Logged


David S
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 2


« Reply #2 on: December 17, 2008, 04:56:03 AM »

I copied that bit from an old code, you are right I don't need to explode it.

I'll try and remove that bit and let you know if it works, thank you very much for your help!

D
Report to moderator   Logged

Pages: [1]   Go Up
Print
 
Jump to:  

Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC | Theme Kani By Fussilet

Page created in 0.042 seconds with 21 queries.