I'm trying to display user/profile information from a MySQL database (created by phpBB3) in an html page. I want to create a public (not related to phpBB) page on a website that will display a list of all users: their names, addresses, phone numbers, websites, and various other profile fields. If all of this information was in one table, I wouldn't have a problem. But phpBB lists custom profile entries in a different table- and I'm not very handy with php or MySQL queries. I can't for the life of me get the tables to merge. I have about 50 different versions of this code, but none of them work the way I want them to.
<?php
$con = mysql_connect( 'hostname', 'username', 'password' );
$db = mysql_select_db( 'dbname' );
//now write a select query to fetch the records from the table
$sql = "select * from phpbb_users";
$query = mysql_query( $sql );
echo "<table border=1>";
//now read and display the entire row of a table one by one looping through it.
//to loop we are using While condition here
while( $row = mysql_fetch_assoc($query) )
{
echo "<tr><td>$row[user_email]</td>";
echo "<td>$row[user_website]</td>";
echo "<td>$row[user_avatar]</td></tr>";
}
echo "</table>";
$sql = "select * from phpbb_profile_fields_data";
$query = mysql_query( $sql );
echo "<table border=1>";
//now read and display the entire row of a table one by one looping through it.
//to loop we are using While condition here
while( $row = mysql_fetch_assoc($query) )
{
echo "<tr><td>$row[pf_name]</td>";
echo "<td>$row[pf_business]</td>";
echo "<td>$row[pf_address]</td>";
echo "<td>$row[pf_phone]</td>";
echo "<td>$row[pf_officer]</td></tr>";
}
echo "</table>";
?>
This displays two separate tables with all of the data that I want to include. I just want these tables to display as one. The second table has the info that I want to display first- but inline with the rest of the data from the first table. I know this is a dumb question. I'm sorry. This sounded SO simple before I tried to make it happen. Thanks for your help! :)
Updated Code:
<?php
$con = mysql_connect( 'hostname', 'username', 'password' );
$db = mysql_select_db( 'dbname' );
$sql = "select * from phpbb_users left join phpbb_profile_fields_data on phpbb_profile_fields_data.user_id = phpbb_users.id";
$query = mysql_query( $sql );
echo "<table>";
while( $row = mysql_fetch_assoc($query) )
{
echo "<tr><td>$row[user_avatar]</td>";
echo "<td>$row[pf_name]</td>";
echo "<td>$row[pf_business]</td>";
echo "<td>$row[pf_address]</td>";
echo "<td>$row[pf_phone]</td>";
echo "<td>$row[user_email]</td>";
echo "<td>$row[user_website]</td>";
echo "<td>$row[pf_officer]</td></tr>";
}
echo "</table>";
?>