result multiple table data?

Reply

Join Date: May 2009
Posts: 38
Reputation: m-hrt is an unknown quantity at this point 
Solved Threads: 0
m-hrt's Avatar
m-hrt m-hrt is offline Offline
Light Poster

result multiple table data?

 
0
  #1
May 16th, 2009
i have 3 tables i want to show the data from them to a page.

table1 "trip"
table2 "seat"
table3 "user_information"

show all the data of table one which is working its showing but how can i show multiple table data any ways.

show all data of trip and seat

from user_information it shows

first_name
last_name

all the tables have id with the same name.



here is the code im using.

  1. <?php
  2. $con = mysql_connect("localhost","root","password");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("online_bus_project", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM trip, seat, user_information ORDER BY `id` DESC LIMIT 1");
  11.  
  12.  
  13. echo "<table border='1'>
  14. <tr>
  15. <th>First Name</th>
  16. <th>Last Name</th>
  17. <th>From</th>
  18. <th>To</th>
  19. <th>Date</th>
  20. <th>Fare</th>
  21. <th>Seat</th>
  22.  
  23. </tr>";
  24.  
  25. while($row = mysql_fetch_array($result))
  26. {
  27. echo "<tr>";
  28. echo "<td>" . $row['first_name'] . "</td>";
  29. echo "<td>" . $row['last_name'] . "</td>";
  30. echo "<td>" . $row['from'] . "</td>";
  31. echo "<td>" . $row['to'] . "</td>";
  32. echo "<td>" . $row['date'] . "</td>";
  33. echo "<td>" . $row['fare'] . "</td>";
  34. echo "<td>" . $row['seat'] . "</td>";
  35. echo "</tr>";
  36. }
  37. echo "</table>";
  38.  
  39. mysql_close($con);
  40. ?>
Last edited by m-hrt; May 16th, 2009 at 8:39 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 38
Reputation: m-hrt is an unknown quantity at this point 
Solved Threads: 0
m-hrt's Avatar
m-hrt m-hrt is offline Offline
Light Poster

Re: result multiple table data?

 
0
  #2
May 17th, 2009
any one?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: result multiple table data?

 
0
  #3
May 17th, 2009
Look into mysql joins or using the where clause and table aliases.

Ex.
  1. SELECT * FROM trip t,seat s,user_information u WHERE t.id = s.id AND t.id = u.id
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 38
Reputation: m-hrt is an unknown quantity at this point 
Solved Threads: 0
m-hrt's Avatar
m-hrt m-hrt is offline Offline
Light Poster

Re: result multiple table data?

 
0
  #4
May 17th, 2009
Originally Posted by kkeith29 View Post
Look into mysql joins or using the where clause and table aliases.

Ex.
  1. SELECT * FROM trip t,seat s,user_information u WHERE t.id = s.id AND t.id = u.id

that's not working??? its not showing any error but its also not showing the result all the tables are blank

check this?

  1. $result = mysql_query("SELECT * FROM trip t,seat s,user_information u WHERE t.id = s.id AND t.id = u.id");
  2.  
  3.  
  4.  
  5.  
  6.  
  7. echo "<table border='1'>
  8. <tr>
  9. <th>First Name</th>
  10. <th>Last Name</th>
  11. <th>From</th>
  12. <th>To</th>
  13. <th>Date</th>
  14. <th>Fare</th>
  15. <th>Seat</th>
  16.  
  17. </tr>";
  18.  
  19. while($row = mysql_fetch_array($result))
  20. {
  21. echo "<tr>";
  22. echo "<td>" . $row['first_name'] . "</td>";
  23. echo "<td>" . $row['last_name'] . "</td>";
  24. echo "<td>" . $row['from'] . "</td>";
  25. echo "<td>" . $row['to'] . "</td>";
  26. echo "<td>" . $row['date'] . "</td>";
  27. echo "<td>" . $row['fare'] . "</td>";
  28. echo "<td>" . $row['seat'] . "</td>";
  29. echo "</tr>";
  30. }
  31. echo "</table>";
  32.  
  33. mysql_close($con);
Last edited by m-hrt; May 17th, 2009 at 11:47 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: result multiple table data?

 
0
  #5
May 17th, 2009
Do you have a column named id in your table. That was just an example.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 2
Reputation: Dani50 is an unknown quantity at this point 
Solved Threads: 0
Dani50 Dani50 is offline Offline
Newbie Poster

Re: result multiple table data?

 
0
  #6
May 17th, 2009
Have you got WHERE twice? It is on my screen twice.
Dani.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 38
Reputation: m-hrt is an unknown quantity at this point 
Solved Threads: 0
m-hrt's Avatar
m-hrt m-hrt is offline Offline
Light Poster

Re: result multiple table data?

 
0
  #7
May 17th, 2009
yes id is in every table? any solutions to this?
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 38
Reputation: m-hrt is an unknown quantity at this point 
Solved Threads: 0
m-hrt's Avatar
m-hrt m-hrt is offline Offline
Light Poster

Re: result multiple table data?

 
0
  #8
May 17th, 2009
Originally Posted by Dani50 View Post
Have you got WHERE twice? It is on my screen twice.
Dani.

that's one time after that is 'AND'

can any one show me how to display that correctly? with one table its working fi9 any ideas.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 38
Reputation: m-hrt is an unknown quantity at this point 
Solved Threads: 0
m-hrt's Avatar
m-hrt m-hrt is offline Offline
Light Poster

Re: result multiple table data?

 
0
  #9
May 17th, 2009
Table (trip) show all from this
* id
* from
* to
* date
* fare

Table (seat) show all from this also
* id
* seat

Table (user_information) show only first_name and last_name
* first_name
* last_name
* email
* address
* city
* province
* contact_no
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: result multiple table data?

 
0
  #10
May 17th, 2009
user_information has no id.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC