Retrieving Data from Two Different Databases

Posted on 16th Feb 2014 by admin

Hello All,

Ran into another problem and would appreciate some help! I have two databases, publications_db (pub_id, title, author, yr, journal, num_pages) and activity_db(member_id,pub_id,date). Basically, when a user is logged in, I want to have an option for them to view the publications they have submitted to the publication database.

In pseudocode, I want to display * from publications_db where the session_id (currently logged in user) matches the activity_db.member id AND activity_db.pub_id matches publications_db.pub_id

Below is the code I was writing although I am sure it is completely off because I am quite new to this stuff! Any help would be greatly appreciated!

Quote$dbhost="localhost";
$dbuser="****";
$dbpass="***";
$dbname1="publications_db";
$dbname2="activity_db";
$db1=mssql_connect($dbhost,$dbuser,$dbpass);
mssql_select_db($dbname1,$db1);
mssql_select_db($dbname2,$db1);

$query="SELECT * FROM publications_db P, activity_db A WHERE $_SESSION['SESS_MEMBER_ID'] = A.member_id AND A.pub_id = P.pub_id;";

echo "<table border cellpadding=2>";

while($info = mysql_fetch_array( $query ))
{
echo "<tr>";
echo "<th>ID:</th><td>".$info['pub_id'] . "</td> ";
echo "<th>Title:</th> <td>".$info['title'] . " </td>";
echo "<th>Author:</th> <td>".$info['author'] . " </td>";
echo "<th>Year:</th> <td>".$info['yr'] . " </td>";
echo "<th>Journal:</th> <td>".$info['journal'] . " </td>";
echo "<th>Pages:</th> <td>".$info['num_pages'] . " </td></tr>";

}

echo "</table>
";
echo "$count_entry Total Entries";

?>

Other forums