Jump to content

php join.....question....


dpabla

Recommended Posts

hey whats up everyone...happy new years..

Question: A user clicks on a particular item on the webpage named Apples which ID = 2- the ID has been passed onto the next page. The newpage.php?id=2 should THAN display the Product name on the page...based on the the logic that the _Get variable would be set to "2" and a JOIN statement would be "ok we got a number 2 from the subcategory table, lets get that same number 2 and look up the product name which is Apple and output the name to the screen. My table is structured below....

Table named Products                       

subcategory_id          Product Name
---------------          --------------
2                                  Apple

Table #2 named: Subcategory
subcategory_id 
---------------
2                             

My code that I am stumped on:
[code]<?php

$result = mysql_query
("select subcategory_id, subcategory_name from products,subcategory
WHERE products.subcategory_id=subcategory.subcategory_id
subcategory_id= {$_GET['sub_id']}");
[/code]

Thanks so much for your help...the part I am stuck on is this: subcategory_id= {$_GET['sub_id']}"    <--------- thats my logical reasoning that the Select query needs to "GET" the variable "2" so that the subcategory ID's are being matched from both tables to output "APPLES"


Link to comment
https://forums.phpfreaks.com/topic/33038-php-joinquestion/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.