Log in

View Full Version : Display data of multiple tables into page?



obtrs
05-17-2009, 12:10 PM
Display data of multiple tables into page?
i have 3 tables i want to show the data from them to a page.

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

show all data of trip and seat table but 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","passwo...
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);
?>



i want this to show data in a straight line in one table?


here are the data list.

Table trip

id
from
to
date
fare

table seat

id
seat

table user_information

this table has information about user which contains user contact no email address and so on but i want to show only first_name and the last_name





also show the last data entered in table ORDER BY `id` DESC LIMIT 1

obtrs
05-17-2009, 08:38 PM
any one?????

here are the tables.

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
* id
* first_name
* last_name
* email
* address
* city
* province
* contact_no

forum_amnesiac
05-18-2009, 01:10 PM
You need to have fields that link the tables together, they can then be "joined" for 'querying'.

This link shows a simple example of this:
http://www.astahost.com/info.php/mysql-multiple-tables_t12815.html

VolcomMky
05-18-2009, 06:53 PM
Correct, first step is to add a Column to the tables seat AND trip.

You should call this column "CustomerID" and then put that customers ID in those columns to they can be linked and have a matching field to be grouped/pulled by.

robertjan
05-18-2015, 01:49 AM
i have a problem with my html form, anybody can help me how to solve this problem, if i enter a text without space the text message over flow to the table.

here is my code

<html>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1” />
<title>Simple HTML Form</title>
<link rel="stylesheet" href="css.css">
</head>
<body>
<!-- Script 2.1 - form.html -->
<div id="wrapper">
<div id="header">header section</div>
<div id="sidebar">
<!--start of sidebar-->
<?php
error_reporting(E_ALL & ~E_NOTICE);

mysql_connect("localhost","root","");
mysql_select_db("db_davao");

$x = mysql_query("SELECT * FROM tbl_students1");
?>
<?php
while($row = mysql_fetch_array($x))
{
$id = $row['id'];
echo "<div id='table'>";
//echo "<br />";
echo "<tr>";
echo "<table border='0' style='resize:both' align='center' cellpadding='0' cellspacing='0'>";
echo "<tr>
<td align='right' width='100' style='fixed'>Name</td><th>:</th><td>".$y['fname']."</td>
</tr>";
echo "<tr>
<td align='right'>Last Name</td><th>:</th><td>".$y['lname']."</td>
</tr>";
echo "<tr>
<td align='right'>Gender</td><th>:</th><td>".$y['gender']."</td>
</tr>";
echo "<tr>
<td align='right'>Age</td><th>:</th><td>".$y['age']."</td>
</tr>";
echo "<tr>
<td align='right'>Comment</td><td>:</td><td><div id='comment'>".$row['comment']."</div></td>
</tr>";
echo " <br /> " ;
echo "</tr>";
echo "</table>";
echo "</div>";
echo " <hr> " ;


//echo "<p align=center><a href=DisplayRecords.php>View Students List</a><p>";
echo "</fieldset>";

}
?>

<!--end of sidebar-->
</div>

the output look like this

5680

Beverleyh
05-18-2015, 07:19 AM
Hi robertjan,

Your post is confusing because you posted it in the PHP forum in a PHP/MYSQL related thread that is 6 years old.

Please can you start a new thread, in the most appropriate forum, and clearly state your problem again (refer back to this thread if you need to).

In your thread, state what you have tried already and/or a copy of the PHP scripts and MYSQL queries that are causing you problems.

If this is an HTML/CSS related problem, please post a link to your actual website so that anyone help you can troubleshoot live in Developer Tools (F12 in most popular browsers)