laserlight;10912839 wrote:I suggest that you show the smallest and simplest script that demonstrates the problem. (That is, do not include things like ".... bunch of page code ...". It should be an example that you can run, and which we could run too if we had the database setup.)
Ok, here's what I have.
I have two databases I need to grab data from on two pages. Examples are below :
Primary DB Table (ie, site.link)
---------------------------
link_desc | link_url
---------------------------
Home | index.php
News | news.php
Roster | roster.php
Secondary DB Table (ie, forum.forum_users)
----------------------------------
user_name | user_email
----------------------------------
Bob Hoskins | bob@aol.com
Rich John | rich@email.org
Brad Layer | blayer@charter.net
I have an include file that is included at the top of every page that contains the database connection. This runs before anything else runs to open the database for queries down the page(s) :
<?php
// DB Connection to Primary Database (filename - dbcon.php) //
$connect = @mysql_connect("localhost", "$user", "$pwd") or die(mysql_error());
$db = @mysql_select_db($db, $connect) or die(mysql_error());
?>
So, with all that built and explained, the page I'm having problems with is exampled below. The Primary DB connection executes via an 'include' command, then I open a connection to the second DB and run a query to get the user data from it. Then, further down, the page executes a query to grab page link data from the Primary DB and build a directory tree.
<?php
// Include DB Connection (filename - forumquery.php) //
include('dbcon.php');
// Create DB Connection to Second DB //
$fconnect = @mysql_connect("localhost", "$fuser", "$fpwd") or die(mysql_error());
$fdb = @mysql_select_db($fdb, $fconnect) or die(mysql_error());
// Get Forum User Data //
$fuser = "SELECT user_name, user_email FROM forum_users ORDER BY user_name ASC";
$fuser_result = @mysql_query($fuser, $fconnect) or die(mysql_error());
while ($frow = mysql_fetch_array($fuser_result)) {
$username = $frow['user_name'];
$useremail = $frow['user_email'];
// Create User Display //
$display_users .= "<div class=user><a mailto:$useremail>$username</a></div><br>";
}
// Create Links Query from Primary Database //
$lnk = "SELECT * FROM link ORDER BY link_id ASC";
$lnk_result = @mysql_query($lnk, $connect) or die(mysql_error());
while ($lrow = mysql_fetch_array($lnk_result)) {
$link_url = $lrow['link_url'];
$link_desc = $lrow['link_desc'];
// Create Navitation Link List //
$display_links .= "· <a href=$link_url>$link_desc</a><br>";
}
?>
However, what happens is I get an error that reads :
The table "forum.link" doesn't exist.
Now either I'm missing something that's so simple I just can't see it, or my DB connection queries are not coded correctly. It's still attempting to grab data from the Secondary database even though I've made a call to the Primary DB '$connect' and not the Secondary's '$fconnect'.