473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multiple database crosstab MYSQL & PHP

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,
Matthew

Code Below:
--------------------------------------------------------------
<?php
require_once('Connections/newsdb.php');
require_once('Connections/basedb.php');
mysql_select_db($database_newsdb, $newsdb);
$res_newsdb = mysql_query("SELECT * FROM tblnews ORDER BY newsdate DESC");
mysql_select_db($database_basedb, $basedb);
$row_newsdb=mysql_fetch_object($res_newsdb);
$res_basedb=mysql_query("SELECT * from tblemployees WHERE
ID=$row_newsdb->postedby");
?>

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

<body>
<table width="500" border="0" class="body01" style='BORDER-COLLAPSE:
collapse'>
<tr>
<td>Latest News:</td>
<td><div align="right"><a href="../phpbb" target="_MainFrame">Bulletin
Board</a></div></td>
</tr>
</table>
<p class="body01">
<?php
echo ("<TABLE BORDER='1' WIDTH=450 style='BORDER-COLLAPSE: collapse'>");
$rows=1;
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>';
$rows++;
}
mysql_free_result($res_newsdb);
echo('</TABLE>');

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

?>
</p>
<p><span class="body01">To email the website manager click </p>
</body>
</html>
---------------------------------------------------------------------
Jul 17 '05 #1
2 2870
Matthew

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

$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
"Matthew Clubb" <ma**@mwclubb.co.uk> wrote in message
news:cn*******************@news.demon.co.uk...
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,
Matthew

Code Below:
--------------------------------------------------------------
<?php
require_once('Connections/newsdb.php');
require_once('Connections/basedb.php');
mysql_select_db($database_newsdb, $newsdb);
$res_newsdb = mysql_query("SELECT * FROM tblnews ORDER BY newsdate DESC");
mysql_select_db($database_basedb, $basedb);
$row_newsdb=mysql_fetch_object($res_newsdb);
$res_basedb=mysql_query("SELECT * from tblemployees WHERE
ID=$row_newsdb->postedby");
?>

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

<body>
<table width="500" border="0" class="body01" style='BORDER-COLLAPSE:
collapse'>
<tr>
<td>Latest News:</td>
<td><div align="right"><a href="../phpbb" target="_MainFrame">Bulletin
Board</a></div></td>
</tr>
</table>
<p class="body01">
<?php
echo ("<TABLE BORDER='1' WIDTH=450 style='BORDER-COLLAPSE: collapse'>");
$rows=1;
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>';
$rows++;
}
mysql_free_result($res_newsdb);
echo('</TABLE>');

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

?>
</p>
<p><span class="body01">To email the website manager click </p>
</body>
</html>
---------------------------------------------------------------------

Jul 17 '05 #2
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

Matt

"Paul Barfoot" <Pa**@theglobalfamily.fsworld.co.uk> wrote in message
news:cn**********@news6.svr.pol.co.uk...
Matthew

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

$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
"Matthew Clubb" <ma**@mwclubb.co.uk> wrote in message
news:cn*******************@news.demon.co.uk...
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,
Matthew

Code Below:
--------------------------------------------------------------
<?php
require_once('Connections/newsdb.php');
require_once('Connections/basedb.php');
mysql_select_db($database_newsdb, $newsdb);
$res_newsdb = mysql_query("SELECT * FROM tblnews ORDER BY newsdate DESC"); mysql_select_db($database_basedb, $basedb);
$row_newsdb=mysql_fetch_object($res_newsdb);
$res_basedb=mysql_query("SELECT * from tblemployees WHERE
ID=$row_newsdb->postedby");
?>

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

<body>
<table width="500" border="0" class="body01" style='BORDER-COLLAPSE:
collapse'>
<tr>
<td>Latest News:</td>
<td><div align="right"><a href="../phpbb" target="_MainFrame">Bulletin Board</a></div></td>
</tr>
</table>
<p class="body01">
<?php
echo ("<TABLE BORDER='1' WIDTH=450 style='BORDER-COLLAPSE: collapse'>");
$rows=1;
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>';
$rows++;
}
mysql_free_result($res_newsdb);
echo('</TABLE>');

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

?>
</p>
<p><span class="body01">To email the website manager click </p>
</body>
</html>
---------------------------------------------------------------------


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Farber | last post by:
I'm not especially new to databases and I have used ODBC before with other data sources, but I cannot seem to get Access 2003 to talk to MySQL 4.0.15. I have MySQL running with new tables...
0
by: CountDraculla | last post by:
Fixing Multiple Database bug in adoDB popular data access layer for php, adoDB can support multiple databases from different provider at time, but not from same provider. what I mean is if you...
4
by: Bob Alston | last post by:
Anyone have experience with converting an access app from Jet database to Mysql? I am specifically looking for any changes I would have to make to my access forms, queries, modules, vba code, etc....
1
by: contact.amarender | last post by:
Hi, I want to export database from MYSQL to Ms Access. Can anybody suggest me a way to do that. thank you, amar
1
by: arulkumara | last post by:
Hi, I have one problem in mysql. how to split single row into multiple columns in mysql. my table structure: id salaryhigh salarymedium salarylow...
0
bilibytes
by: bilibytes | last post by:
hi, i am trying to UPDATE multiple rows with mysql. I know how to do it with multiple queries but i think it would be less resource consuming generating mysql query code with php and update all...
7
by: CoachDave48 | last post by:
I am a rookie coder and got some great help from Marcus last year so I thought I would make another request. I am trying to retrieve all boys in one household into a form and edit the individual...
1
by: newphpcoder | last post by:
I changed my database from mysql 4.1.10 to mysql 5.0 and I encountered error in my calendar event page. The output of my calendar date was change instead of date it becomes “>” and also when I press...
0
by: prakashghai | last post by:
After spending 3 days on internet and struggling with so many different forums , i have found a match and similar case of my problem here. Friends, I am zero in PHP, but still i have managed to do...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.