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.

<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("online_bus_project", $con);

$result = mysql_query("SELECT * FROM trip, seat, user_information ORDER BY `id` DESC LIMIT 1");  


echo "<table border='1'>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>From</th>
<th>To</th>
<th>Date</th>
<th>Fare</th>
<th>Seat</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['first_name'] . "</td>";
  echo "<td>" . $row['last_name'] . "</td>";
  echo "<td>" . $row['from'] . "</td>";
  echo "<td>" . $row['to'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['fare'] . "</td>";
  echo "<td>" . $row['seat'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

Look into mysql joins or using the where clause and table aliases.

Ex.

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

Look into mysql joins or using the where clause and table aliases.

Ex.

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?

$result = mysql_query("SELECT * FROM trip t,seat s,user_information u WHERE t.id = s.id AND t.id = u.id");  





echo "<table border='1'>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>From</th>
<th>To</th>
<th>Date</th>
<th>Fare</th>
<th>Seat</th>

</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['first_name'] . "</td>";
  echo "<td>" . $row['last_name'] . "</td>";
  echo "<td>" . $row['from'] . "</td>";
  echo "<td>" . $row['to'] . "</td>";
  echo "<td>" . $row['date'] . "</td>";
  echo "<td>" . $row['fare'] . "</td>";
  echo "<td>" . $row['seat'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

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.

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

yes it has id i did mistake on writing its named same as id kkeith29?

any solution?

It should work then. Something else has to be wrong.

add this: or die(mysql_error()); to the end of the mysql_query function. That way you can see if there are any database problems.

Comments
thanx for the help

i have done it like this but its not showing contact number why????

because its a number that's why?

try this..

select  t.id,t.from,t.to,t.date,t.fare,s.seat,u.first_name,u.last_name from trip t,seat s,user_information u where t.id=s.id
Comments
thanx for the help

thanx for the help all really appreciate.

thanx
Poojasrivastava rep added also for kkeith29 thanx

This article has been dead for over six months. Start a new discussion instead.