Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying specific results from a table

Status
Not open for further replies.

rskuse

Technical User
Jul 18, 2002
74
GB
I have a relational database with two tables that both hold subcat_id. What I want to do is when a link is clicked to return results from the second table that have the same subcat_id as the link that has been clicked.

For example:
subcat_id: 1 = SubCat1
subcat_id: 2 = SubCat2
subcat_id: 3 = SubCat3

When I click on SubCat1 results should be returned from the second table with a subcat_id of 1 but as it is all results are being returned which I don't want!!

The code I am using for the link is
<a href=&quot;topic.php?subcat_id=<?php echo $row_SubCategory['subcat_id']; ?>&quot;><?php echo $row_SubCategory['subcat']; ?></a>

I know I haven' explained this very well but if anyone can make sense of what I'm trying to achieve I would very much appreciate some help!

Thankyou in advance...

Rachel
 
try a join:
$sql=&quot;select subcat from Table1 a,Table2 b where a.SubCatid=b.sub_catid&quot;

Known is handfull, Unknown is worldfull
 
That's what I do originally to display the values from the first table:
$query_SubCategory = &quot;SELECT * FROM subcat, topic WHERE subcat.subcat_id = topic.subcat_id&quot;;

but it's the data from 'subcat' that I want to link to the data from 'topic' on a new page (topic.php)

I'm getting very confused!!
 
&quot;SELECT * FROM subcat, topic WHERE subcat.subcat_id = topic.subcat_id and subcat.subcat_id='ID CLICKED HERE'&quot;;

am i clear?

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top