User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 363,433 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,133 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 264 | Replies: 2
Reply
Join Date: Dec 2007
Posts: 14
Reputation: webguru07 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
webguru07 webguru07 is offline Offline
Newbie Poster

mysql_fetch_array for multiple tables

  #1  
Apr 24th, 2008
I need to get information from 2 tables in the same mysql database

  1. $sql = mysql_query("SELECT * FROM notes, customers WHERE `to`='next' LIMIT 5");
  2.  
  3. while($a = mysql_fetch_array($sql)){
  4.  
  5. $row_color = ($row_count % 2) ? "#EFEFEF" : "#FFFFFF";
  6.  
  7. echo("<tr bgcolor=\"$row_color\">
  8. <td height=\"25\">" . $a['custid'] . "</td>
  9. <td height=\"25\">" . $a['name'] . "</td>
  10. <td>" . $a['ebay'] . "</td>
  11. <td>" . $a['title'] . "</td>
  12. <td>" . $a['type'] . "</td>
  13. </tr>");
  14.  
  15. $row_count++;
  16. }

The name and ebay fields are in the customer table and the rest are in the notes table. The code above doesnt produce any error just no rows are displayed
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2007
Location: St. Vincent and the Grenadines, Caribbean
Posts: 903
Reputation: scru is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 38
Featured Poster
scru's Avatar
scru scru is offline Offline
Posting Shark

Re: mysql_fetch_array for multiple tables

  #2  
Apr 24th, 2008
you cant query two tables aat once. Either do them one at a time or make a stored procedure. I don't know anything about mysql so I cant help with the stored procedure.
Half and a half meck a whole, and I donned it a hundrid purcent
Reply With Quote  
Join Date: Apr 2008
Posts: 12
Reputation: prethum is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
prethum prethum is offline Offline
Newbie Poster

Re: mysql_fetch_array for multiple tables

  #3  
Apr 24th, 2008
is the talbes realted to each othere and the primary key of one table should be the foreign of the other tbale that u are trying to get datafrom
if soo
then you can use join
select from note, coustomers where note.id =costomer.id and to = 'next';
u can get more information on this from
http://www.tizag.com/mysqlTutorial/mysqljoins.php
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC