Hello everyone!
Here`s a simple task and a terrible mistakes…..
simply I have 2 mysql tables.
One is Quotes with id_quote,id_author and quote
Second is Authors with id_author and name_author.
What I`m creating.
A simple random function who gives me back some number id of a quote and finds the author…
Here is the code
[QUOTE]
function random_quote()
{
$rs=mysql_query(‘SELECT MAX(id_quote) AS id_quote FROM quotes ‘);
$quote_random=rand(1,(intval($rs)));
return $quote_random;
}
function settings()
{
}
function main()
{
//извеждане на правилния автор
echo ‘Who Said It?’;
echo ‘<br />’;
$rs=mysql_query(‘SELECT * FROM quotes
WHERE id_quote=”‘.random_quote().'” ‘);
$quote_info=mysql_fetch_assoc($rs);
echo $quote_info[‘quote’];
echo ‘<br />’;
echo ‘<br />’;
//ПРАВИЛНИЯТ ОТГОВОР
$rs=mysql_query(‘SELECT * FROM authors
WHERE id_author=’.$quote_info[‘id_author’].’ ‘);
while($row=mysql_fetch_assoc($rs))
{
echo $row[‘name_author’];
}
echo ‘<br />’;
print_r ($quote_info);
}
The problem is that!
I have 10 quotes in the db.
However this random function gives me everytime 5…
I deleted the function,try different method… and nothing is working!