/    Sign up×
Community /Pin to ProfileBookmark

I`m going to shoot myself !! What the hell is that sql doing ?!?

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 />’;

//&#1055;&#1056;&#1040;&#1042;&#1048;&#1051;&#1053;&#1048;&#1071;&#1058; &#1054;&#1058;&#1043;&#1054;&#1042;&#1054;&#1056;
$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);

}

[/QUOTE]

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!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@behkoauthorMar 09.2012 — Ok Im done with the problem!<br/>
Please don
t ask me how,because I don`t know how I repaired it ?
×

Success!

Help @behko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...