PDA

View Full Version : database question


sifuhall
05-25-2002, 01:48 PM
I want to include a random entry from a table in another database. My script returns the random entry just fine, but when I call it from vBulletin it doesn't work.

Here is the error I get from vBulletin:

Warning: 1 is not a valid MySQL-Link resource in /home/virtual/site19/fst/var/www/html/discussion/admin/db_mysql.php on line 120


Here is the script (with the userid and password removed):

function getDidYouKnow(&$didyouknow) {
$newdb = mysql_connect("localhost", $mydbuser, $mydbpass);

// get random entry
$myquery = "SELECT * FROM didyouknow ORDER BY RAND() LIMIT 1";
$myresult = mysql_db_query($mydbname, $myquery);
if ($myresult) {
$dykr = mysql_fetch_array($myresult);
$didyouknow = $dykr["info"];
}
mysql_free_result($myresult);
mysql_close($newdb);
}

And I call this in the phpinclude template like this:

// get common page vars
require "***edited path to the file ***/common.php";
// get Did You Know
getDidYouKnow($didyouknow);


So why does this screw up vBulletin's database reference?

sifuhall
05-26-2002, 01:01 AM
Got it, mysql_select_db was the solution.

Regit
08-17-2002, 01:16 AM
you got it ? how ?
i have the same problem , please post your solution code here !

sifuhall
08-17-2002, 12:28 PM
Just use mysql_select_db to reselect your forum database when you exit your routine