stupid question
Posted: Fri Jul 18, 2003 3:35 am
hey i am brand new to php and i have what could very easily be a stupid question.
i am using random quote generator to implement in my new website, and i would like to make it easy for the user to randomly come up with another quote (without having to refresh the page). is this even possible?
it would be nice if there was some way i could do it through a simple HTML link.
thanks
(i have included the code for the generator here - much of it is from a tutorial i found on evilwalrus.com)
i am using random quote generator to implement in my new website, and i would like to make it easy for the user to randomly come up with another quote (without having to refresh the page). is this even possible?
it would be nice if there was some way i could do it through a simple HTML link.
thanks
(i have included the code for the generator here - much of it is from a tutorial i found on evilwalrus.com)
Code: Select all
<?php
function randomQuote() {
$dbcx = mysql_connect(localhost, username, password);
if(!$dbcx) {
echo "there was an error connecting to the database!<br>" ;
exit();
}
if(!@mysql_select_db("amdayton_text",$dbcx)) {
echo "there was an error selecting the database!<br>" . mysql_error();
exit();
}
$result = mysql_query("SELECT * FROM quotes");
if(!$result) {
echo "there was an error reading the data!" . mysql_error();
exit();
}
$num_rows = mysql_num_rows($result);
$rand_row = rand(0, $numRows + 1);
$result = mysql_query("SELECT * FROM quotes LIMIT $rand_row, 1");
if(!$result) {
echo "there was an error reading the data!" . mysql_error();
exit();
}
while($row = mysql_fetch_array($result)) {
$quoteArrayї0] = $rowїquote];
$quoteArrayї1] = $rowїauthor];
}
return $quoteArray;
}
?>