I can understand that's probably the case but I just can't spot the error, here's the relevant part of the file (copied straight from it):
<?
// set up some common variables
// server name
$server = "localhost";
// username
$user = "test";
// password
$pass = "test";
// database to use
$db = "rhianan";
// function to insert a random quote
function quote() {
// initialise database connection
if (!$connection = mysql_connect($server, $user, $pass)) {
echoError("Error connection to database");
}
// select database to work with
if (!mysql_select_db($db, $connection)) {
echoError("Error selecting database");
}
// execute query to select all the quotes
if (!$result = mysql_query("select quote from quotes;", $connection)) {
echoError("Error running query");
}
// set $num_quotes to the number of quotes in the database
$num_quotes = mysql_num_rows($result);
$num_quotes--;
for ($i = 1; $i < $num_quotes; $i++) {
$tmp = mysql_fetch_row($result);
echo "$tmp<br>";
}
// seed with microseconds since last "whole" second
srand ((double) microtime() * 1000000);
$randval = rand(0, $num_quotes);
// get appropriate quote
mysql_data_seek($result, $randval);
$quote = mysql_fetch_row($result);
// show quote
echo "$quote";
// memory flush
mysql_free_result($result);
}
function echoError($errorString) {
echo "<p><b><font color=\"#FF0000\">$errorString: ".mysql_error()."</font></b><p>";
}
?>
all i did to get this working is change the '$db = "rhianan";' line to "define(db, "rhianan");' and alter the mysql_select_db line accordingly.
b4 anyone points this out, I know it doesn't work properly (e.g. return a random record from the table) that's ok, i know this and will sort it later, at the moment I'd like to know why I was having this select_db problem.