By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

show data of multiple tables?

P: 27
show data of multiple tables?
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.

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



also show the last line which is entered in the id



here is the code im using.

Expand|Select|Wrap|Line Numbers
  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. ?>
May 17 '09 #1
Share this Question
Share on Google+
8 Replies


P: 27
any one????...............
May 17 '09 #2

prabirchoudhury
100+
P: 162
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3. $con = mysql_connect("localhost","root","password"); 
  4. if (!$con) 
  5.   { 
  6.   die('Could not connect: ' . mysql_error()); 
  7.   } 
  8.  
  9.   mysql_select_db("online_bus_project", $con); 
  10.  
  11.   $result_trip = mysql_query("SELECT * FROM trip where booking_id=$booking_id"); 
  12.  
  13.   $result_seat = mysql_query("SELECT * FROM trip where booking_id=$booking_id"); 
  14.  
  15.   $result_user = mysql_query("SELECT * FROM user_information where user_information_id = $id and booking_id=$booking_id"); 
  16.  
  17.   $csr_trip = mysql_query($result_trip);
  18.   $csr_seat = mysql_query($result_seat);
  19.   $csr_user = mysql_query($result_user);
  20.   // get the if is in database
  21.     $num_trip = mysql_num_rows($csr_trip);
  22.     $num_seat = mysql_num_rows($csr_seat);
  23.     $num_user = mysql_num_rows($csr_user);
  24.  
  25.  
  26.           if ($num_trip > 0){ 
  27.            while ($row=mysql_fetch_array($csr_trip)) {
  28.   //trip table
  29. echo "<table border='1'> 
  30. <tr> 
  31. <th>First Name</th> 
  32. <th>Last Name</th> 
  33. <th>From</th> 
  34. <th>To</th> 
  35. <th>Date</th> 
  36. <th>Fare</th> 
  37. <th>Seat</th> 
  38.  
  39. </tr>"; 
  40.  
  41. while($row = mysql_fetch_array($result)) 
  42.   { 
  43.   echo "<tr>"; 
  44.   echo "<td>" . $row['first_name'] . "</td>"; 
  45.   echo "<td>" . $row['last_name'] . "</td>"; 
  46.   echo "<td>" . $row['from'] . "</td>"; 
  47.   echo "<td>" . $row['to'] . "</td>"; 
  48.   echo "<td>" . $row['date'] . "</td>"; 
  49.   echo "<td>" . $row['fare'] . "</td>"; 
  50.   echo "<td>" . $row['seat'] . "</td>"; 
  51.   echo "</tr>"; 
  52.   } 
  53. echo "</table>"; 
  54. }
  55.  
  56. // seat table
  57.  if ($num_seat > 0){ 
  58.            while ($row=mysql_fetch_array($csr_seat)) {
  59.   //
  60. echo "<table border='1'> 
  61. <tr> 
  62. <th>First Name</th> 
  63. <th>Last Name</th> 
  64. <th>From</th> 
  65. <th>To</th> 
  66. <th>Date</th> 
  67. <th>Fare</th> 
  68. <th>Seat</th> 
  69.  
  70. </tr>"; 
  71.  
  72. while($row = mysql_fetch_array($result)) 
  73.   { 
  74.   echo "<tr>"; 
  75.   echo "<td>" . $row['first_name'] . "</td>"; 
  76.   echo "<td>" . $row['last_name'] . "</td>"; 
  77.   echo "<td>" . $row['from'] . "</td>"; 
  78.   echo "<td>" . $row['to'] . "</td>"; 
  79.   echo "<td>" . $row['date'] . "</td>"; 
  80.   echo "<td>" . $row['fare'] . "</td>"; 
  81.   echo "<td>" . $row['seat'] . "</td>"; 
  82.   echo "</tr>"; 
  83.   } 
  84. echo "</table>"; 
  85. }
  86. // user table
  87.  
  88.  if ($num_user > 0){ 
  89.            while ($row=mysql_fetch_array($csr_user)) {
  90.   //
  91. echo "<table border='1'> 
  92. <tr> 
  93. <th>First Name</th> 
  94. <th>Last Name</th> 
  95. <th>From</th> 
  96. <th>To</th> 
  97. <th>Date</th> 
  98. <th>Fare</th> 
  99. <th>Seat</th> 
  100.  
  101. </tr>"; 
  102.  
  103. while($row = mysql_fetch_array($result)) 
  104.   { 
  105.   echo "<tr>"; 
  106.   echo "<td>" . $row['first_name'] . "</td>"; 
  107.   echo "<td>" . $row['last_name'] . "</td>"; 
  108.   echo "<td>" . $row['from'] . "</td>"; 
  109.   echo "<td>" . $row['to'] . "</td>"; 
  110.   echo "<td>" . $row['date'] . "</td>"; 
  111.   echo "<td>" . $row['fare'] . "</td>"; 
  112.   echo "<td>" . $row['seat'] . "</td>"; 
  113.   echo "</tr>"; 
  114.   } 
  115. echo "</table>"; 
  116. }
  117. mysql_close($con); 
  118. ?> 
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
May 17 '09 #3

P: 27
prabir i want this to be look like a ticket? what should i do?




Expand|Select|Wrap|Line Numbers
  1.  <?php
  2. $con = mysql_connect("localhost","root","autodeskmaya");
  3. if (!$con)
  4.   {
  5.   die('Could not connect: ' . mysql_error());
  6.   }
  7.  
  8. mysql_select_db("online_bus_project", $con);
  9.  
  10.  
  11.  
  12. echo "<table border='1' cellpadding='5' cellspacing='3' align='center' bgcolor='#ececec'>
  13. <tr>
  14.  
  15. <th>Online Bus Ticket Reservation System - Traveling Ticket</th> 
  16.  
  17. </tr>";
  18.  
  19. echo "</table>";
  20.  
  21.  
  22.  
  23. $result3 = mysql_query("SELECT ticket FROM ticket_number ORDER BY RAND() LIMIT 1");
  24.  
  25.  
  26. echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
  27. <tr>
  28.  
  29. <th>Ticket Number</th> 
  30.  
  31. </tr>";
  32.  
  33. while($row3 = mysql_fetch_array($result3))
  34.   {
  35.   echo "<tr>";
  36.   echo "<td>" . $row3['ticket'] . "</td>";
  37.   echo "</tr>";
  38.   }
  39. echo "</table>";
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. //SELECT * FROM table ORDER BY RAND() LIMIT 1
  48.  
  49.  
  50.  
  51.  
  52. $result2 = mysql_query("SELECT first_name, last_name FROM user_information ORDER BY `id` DESC LIMIT 1");  
  53.  
  54.  
  55. echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
  56. <tr>
  57.  
  58. <th>Name</th> 
  59. <th>Last Name</th>
  60.  
  61.  
  62.  
  63.  
  64. </tr>";
  65.  
  66. while($row2 = mysql_fetch_array($result2))
  67.   {
  68.   echo "<tr>";
  69.   echo "<td>" . $row2['first_name'] . "</td>";
  70.   echo "<td>" . $row2['last_name'] . "</td>";
  71.   echo "</tr>";
  72.   }
  73. echo "</table>";
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. $result = mysql_query("SELECT * FROM trip ORDER BY `id` DESC LIMIT 1");  
  81.  
  82.  
  83. echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
  84. <tr>\n
  85. <th>From</th>
  86. <th>To</th>
  87. <th>Date</th>
  88. <th>Paid Amount</th>
  89.  
  90.  
  91.  
  92. </tr>";
  93.  
  94. while($row = mysql_fetch_array($result))
  95.   {
  96.   echo "<tr>";
  97.   echo "<td>" . $row['gender'] . "</td>";
  98.   echo "<td>" . $row['country'] . "</td>";
  99.   echo "<td>" . $row['date'] . "</td>";
  100.   echo "<td>" . $row['fare'] . "</td>";
  101.   echo "</tr>";
  102.   }
  103. echo "</table>";
  104.  
  105.  
  106. $result1 = mysql_query("SELECT * FROM seat ORDER BY `id` DESC LIMIT 1");  
  107.  
  108.  
  109. echo "<table border='1' cellpadding='5' cellspacing='3' align='center' >
  110. <tr>\n
  111. <th>Seat</th>
  112.  
  113. </tr>";
  114.  
  115. while($row1 = mysql_fetch_array($result1))
  116.   {
  117.   echo "<tr>";
  118.   echo "<td>" . $row1['seat'] . "</td>";
  119.   echo "</tr>";
  120.   }
  121. echo "</table>";
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. mysql_close($con);
  131. ?> 
May 18 '09 #4

P: 27
i have done this to achive result but tables are mess? i want this to show a ticket look like a ticket havent worked with php styling and tables?
May 18 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
@obtrs
there's nothing like php styling (the styling is done via HTML/CSS), despite when you refer to the source code writing style…

best is you draw how the ticket should look like, construct the according HTML/CSS and make PHP print it this way.
May 18 '09 #6

P: 27
thanx.... but im trying inside of php tag its done via html but what when we access database tables which are inside php tags
<?php

?>
May 18 '09 #7

Dormilich
Expert Mod 5K+
P: 8,639
without knowing what the output shall look like, there's no much sense to play around in PHP.

make an example page (using example values) and make it look like you want it to be (we worry about the PHP issues later). once that is displaying correctly, we can consider how to get PHP printing it this way.
May 18 '09 #8

P: 27
thanx for the help im looking forward to it thanx.
May 18 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.