
December 8th, 2003, 03:47 AM
|
|
|
|
Join Date: Apr 2007
Location: Lexington, KY, USA
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
joining two tables
I have 2 tables: companies and categories with one relative field 'category_id'. I want to display a list of the categories where each each category links to a list of companies that have that same category_id (pretty standard application I presume). I'm new to this though and haven't been too successful with joining tables so any advice you could give would be greatly appreciated.
php Code:
Original
- php Code |
|
|
|
<? function display($show_cat) { categories($categories); } function categories($categories) { $sql = "select * from categories"; $category_id = $row["category_id"]; printf("<p><a href="?category_id=%s ">%s</a>n<br>", $row["category_id"], $row["category"]); } } function display_cat($show_list) { cat_list($cat_list); } function cat_list($cat_list) { $sql = "select distinct * from companies,categories where companies.category_id = categories.category_id and categories.category_id = '$category_id'"; printf("<p><a href="?company_id=%s ">%s</a>n%sn<br>%sn<br>", $row["company_id"], $row["name"], $row["category_id"], $row["services"]); } } head("Category"); display_cat($show_list); else: head("Listing"); display($show_cat); endif; ?>
The problem is that when you click on a category link none of the companies show up. I thought that since the category_id variable was passed through the URL that I could call that variable again in the cat_list function.
I hope this makes sense, thanks for your time.
|