Multiple database crosstab MYSQL & PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Please help, a bit new to this!

I've got two databases and I'm trying to look with values from one table in
one database and then look up a name from the other database, the two tables
are linked where  'postedby' in my newsdb database refers to 'ID' in my
tblemployees table in my basedb database.
All I get is one name shown and 6 records where there are actually 7.

Any help would be greatly appreciated.

Kind Regards,

Code Below:
mysql_select_db($database_newsdb, $newsdb);
$res_newsdb = mysql_query("SELECT * FROM tblnews ORDER BY newsdate DESC");
mysql_select_db($database_basedb, $basedb);
$res_basedb=mysql_query("SELECT * from tblemployees WHERE

<link href="body01.css" rel="stylesheet" type="text/css">

<table width="500" border="0" class="body01" style='BORDER-COLLAPSE:
    <td>Latest News:</td>
    <td><div align="right"><a href="../phpbb" target="_MainFrame">Bulletin
<p class="body01">
echo ("<TABLE BORDER='1' WIDTH=450 style='BORDER-COLLAPSE: collapse'>");
while($rows <= 10)
$res_news = mysql_fetch_array($res_newsdb);
$res_base = mysql_fetch_array($res_basedb);
$ndate = $res_news['newsdate'];
echo ('<TR><TD><FONT SIZE=-2><div align="center">' . $ndate .
'</div></FONT></TD><TD>' .
    $res_news['news']) . '</TD><TD>' .
     $res_base['IDname'] . '</TD></TR>';

echo("<BR /><P><A HREF='addnews.php'>Add news</A></P>");

<p><span class="body01">To email the website manager click </p>

Re: Multiple database crosstab MYSQL & PHP


I was shown recently how you can query more than one database in one SQL

$results = mysql_query("SELECT newsdb.tblnews.*,  basedb.tblemployees .*
FROM newsdb.tblnews INNER JOIN basedb.tblemployees ON
newsdb.tblnews.postedby = basedb.tblemployees.ID ORDER BY
newsdb.tblnews.newsdate DESC");

You only need one of the connections to a database (either will do). Until I
was shown this I thought it was one connection, one database.

Paul Barfoot

Quoted text here. Click to load it

Re: Multiple database crosstab MYSQL & PHP

Oh my god, I was sure I'd tried that! but anyway,

Thanks very much for solving the frustration of my last week!!!

Its much simpler when you know how

Thanks again


Quoted text here. Click to load it
Quoted text here. Click to load it
Quoted text here. Click to load it

Site Timeline