zero-perfoliate
zero-perfoliate

Author Topic: SQL: link to return only selected results  (Read 1777 times)

Offline David S

  • New PHP Members
  • Posts: 2
  • Karma: +0/-0
SQL: link to return only selected results
« on: December 17, 2008, 12:26:13 AM »
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

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: SQL: link to return only selected results
« Reply #1 on: December 17, 2008, 10:45:14 AM »
why are you exploding it if it only contains books when they are clicked on?

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

Offline David S

  • New PHP Members
  • Posts: 2
  • Karma: +0/-0
Re: SQL: link to return only selected results
« Reply #2 on: December 17, 2008, 12:56:03 PM »
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