php - Merging 2 tables with 1 common field- MySQL -


i'm trying display user/profile information mysql database (created phpbb3) in html page. want create public (not related phpbb) page on website display list of users: names, addresses, phone numbers, websites, , various other profile fields. if of information in 1 table, wouldn't have problem. phpbb lists custom profile entries in different table- , i'm not handy php or mysql queries. can't life of me tables merge. have 50 different versions of code, none of them work way want them to.

<?php  $con = mysql_connect( 'hostname', 'username', 'password' ); $db =  mysql_select_db( 'dbname' );  //now write select query fetch records table  $sql = "select * phpbb_users"; $query = mysql_query( $sql );  echo "<table border=1>";  //now read , display entire row of table 1 one looping through it. //to loop 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 * phpbb_profile_fields_data"; $query = mysql_query( $sql );  echo "<table border=1>";  //now read , display entire row of table 1 one looping through it. //to loop 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 2 separate tables of data want include. want these tables display one. second table has info want display first- inline rest of data first table. know dumb question. i'm sorry. sounded simple before tried make happen. help! :)

updated code:

<?php  $con = mysql_connect( 'hostname', 'username', 'password' ); $db =  mysql_select_db( 'dbname' );  $sql = "select * 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>";  ?> 

i dont know table structure, below example:

select * phpbb_users join phpbb_profile_fields_data on phpbb_profile_fields_data.user_id = phpbb_users.id 

nb: use '...left join...' if 2nd table might not have matching row

$sql = " select *  phpbb_users  left join phpbb_profile_fields_data on       phpbb_profile_fields_data.user_id = phpbb_users.id "; // question: should above phpbb_users.user_id mentioned in comments $query = mysql_query( $sql );   echo '<table>';  while( $row = mysql_fetch_assoc($query) ) {      echo '<tr>';      echo '<td>' . $row['user_avatar'] . '</td>';      // ...      echo '<td>' . $row['pf_officer'] . '</td>';      echo '</tr>'; }  echo '</table>'; 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -