Jump to content

displaying results from multiple tables


unplugged_web

Recommended Posts

I want to be able to display results from multiple tables (all in the same database) on the page. Each of the tables have a 'user_id; that is the same for each row and I want to group the results for each user_id. So the the name, email, phone number and address (all stored in different tables) for user_id 23 are all displayed together.I tried:

<?php$con = @mysql_connect('host', 'user', 'password');if (!$con) {die('<p>Unable to connect to the database server at this time.</p>' . mysql_error());}mysql_select_db("database", $con);$result = mysql_query('SELECT name FROM users');$result = mysql_query('SELECT email FROM emails');$result = mysql_query('SELECT phone FROM contacts');$result = mysql_query('SELECT address FROM postal');$list->m_sql_where = "u.user_id=" . $g_user['user_id'] . "";$list->m_is_me = true;$page->add($list);while ($row = mysql_fetch_array($result)) {echo '<p>' . $row['name'] . ['email'] . ['phone'] . ['address'] . '</p>';}?>

but just got a blank pageThanks

Link to comment
Share on other sites

:) that isn't doing what you think - every time you call mysql_query() the resource from the previous one just disappears. I think you need to read up on JOIN: http://www.w3schools.com/sql/sql_join.aspAlso, in the echo you can't take shortcuts in the way you have, it needs to be something like
echo "<p>{$row['name']} {$row['email']} {$row['phone']} {$row['address']}</p>";

Link to comment
Share on other sites

:) that isn't doing what you think - every time you call mysql_query() the resource from the previous one just disappears. I think you need to read up on JOIN: http://www.w3schools.com/sql/sql_join.aspAlso, in the echo you can't take shortcuts in the way you have, it needs to be something like
echo "<p>{$row['name']} {$row['email']} {$row['phone']} {$row['address']}</p>";

Okay, thanks. I'll have a look at that page
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...