473,804 Members | 3,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('C onnections/newsdb.php');
require_once('C onnections/basedb.php');
mysql_select_db ($database_news db, $newsdb);
$res_newsdb = mysql_query("SE LECT * FROM tblnews ORDER BY newsdate DESC");
mysql_select_db ($database_base db, $basedb);
$row_newsdb=mys ql_fetch_object ($res_newsdb);
$res_basedb=mys ql_query("SELEC T * from tblemployees WHERE
ID=$row_newsdb->postedby");
?>

<html>
<link href="body01.cs s" 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="_MainFr ame">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_arr ay($res_newsdb) ;
$res_base = mysql_fetch_arr ay($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_resu lt($res_newsdb) ;
echo('</TABLE>');

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

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

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

$results = mysql_query("SE LECT newsdb.tblnews. *, basedb.tblemplo yees .*
FROM newsdb.tblnews INNER JOIN basedb.tblemplo yees ON
newsdb.tblnews. postedby = basedb.tblemplo yees.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.c o.uk> wrote in message
news:cn******** ***********@new s.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('C onnections/newsdb.php');
require_once('C onnections/basedb.php');
mysql_select_db ($database_news db, $newsdb);
$res_newsdb = mysql_query("SE LECT * FROM tblnews ORDER BY newsdate DESC");
mysql_select_db ($database_base db, $basedb);
$row_newsdb=mys ql_fetch_object ($res_newsdb);
$res_basedb=mys ql_query("SELEC T * from tblemployees WHERE
ID=$row_newsdb->postedby");
?>

<html>
<link href="body01.cs s" 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="_MainFr ame">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_arr ay($res_newsdb) ;
$res_base = mysql_fetch_arr ay($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_resu lt($res_newsdb) ;
echo('</TABLE>');

echo("<BR /><P><A HREF='addnews.p hp'>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**@theglobal family.fsworld. co.uk> wrote in message
news:cn******** **@news6.svr.po l.co.uk...
Matthew

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

$results = mysql_query("SE LECT newsdb.tblnews. *, basedb.tblemplo yees .*
FROM newsdb.tblnews INNER JOIN basedb.tblemplo yees ON
newsdb.tblnews. postedby = basedb.tblemplo yees.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.c o.uk> wrote in message
news:cn******** ***********@new s.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('C onnections/newsdb.php');
require_once('C onnections/basedb.php');
mysql_select_db ($database_news db, $newsdb);
$res_newsdb = mysql_query("SE LECT * FROM tblnews ORDER BY newsdate DESC"); mysql_select_db ($database_base db, $basedb);
$row_newsdb=mys ql_fetch_object ($res_newsdb);
$res_basedb=mys ql_query("SELEC T * from tblemployees WHERE
ID=$row_newsdb->postedby");
?>

<html>
<link href="body01.cs s" 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="_MainFr ame">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_arr ay($res_newsdb) ;
$res_base = mysql_fetch_arr ay($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_resu lt($res_newsdb) ;
echo('</TABLE>');

echo("<BR /><P><A HREF='addnews.p hp'>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
2754
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 defined, but I cannot get a connection to those tables via ODBC using MyODBC 3.51. Can anyone point the way? Many thanks,
0
3249
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 instantiate two adoDB connection like this $db1 = &NewAdoConnection ("mysql"); $db1 = &NewAdoConnection ("oracle"); then you can run queries simultaneously from these connections. but if
4
3326
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. I understand there are some data format differences in text field types and date types that need to be addressed if converting from Jet to Mysql. But other than things that have to be addressed when converting, what other changes must I make?...
1
8571
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
4166
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 ********************************************** 1 1000 100 1 2 2000 200 2
0
8049
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 one single step. here is the method i usually employ: $value_column_1 = array(); $value_column_2 = array(); for($i = 0; $i<= $number_of_updates; $i++){
7
4592
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 rows and then update with one submit button. I can retrieve the rows and populate the form but the update does not work. Thanks in advance Here is the testing code obtained from http://www.phpeasystep.com/mysql/10.html
1
1377
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 the button to move to another month I can’t move to another month. I have no idea why it happened. Here is the old calendar code: <?php $dbCnx = @mysql_connect("localhost","", "") or die('Could not Connect to the database')...
0
1356
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 something to fulfill my requirement. I am stuck with one thing now..So i need help on.... I am using one html+php form to submit database into mysql. I created a display of that table through php script on a webpage. Now i want a datepicker...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9157
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.