Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old December 8th, 2003, 03:47 AM
t_macdonald t_macdonald is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Lexington, KY, USA
Posts: 9 t_macdonald User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to t_macdonald
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
  1.  
  2. <?
  3. function display($show_cat) {
  4.         categories($categories);
  5.     }
  6.  
  7. function categories($categories) {
  8.         $sql = "select * from categories";
  9.         $result = mysql_query($sql);
  10.         $category_id = $row["category_id"];
  11.         while($row = mysql_fetch_array($result)) {
  12.         printf("<p><a href="?category_id=%s">%s</a>n<br>", $row["category_id"], $row["category"]);
  13.         }
  14.     }
  15.  
  16. function display_cat($show_list) {
  17.         cat_list($cat_list);
  18.     }
  19.  
  20. function cat_list($cat_list) {
  21.         $sql = "select distinct * from companies,categories where companies.category_id = categories.category_id and categories.category_id = '$category_id'";
  22.         $result = mysql_query($sql);
  23.         while($row = mysql_fetch_array($result)) {
  24.         printf("<p><a href="?company_id=%s">%s</a>n%sn<br>%sn<br>", $row["company_id"], $row["name"], $row["category_id"], $row["services"]);
  25.         }
  26.     }
  27.    
  28.  
  29. if(isset($category_id)):
  30.     head("Category");
  31.     display_cat($show_list);
  32. else:
  33.     head("Listing");
  34.     display($show_cat);
  35.  
  36. endif;
  37. ?>


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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > joining two tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT