472,802 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,802 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 2830
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.