|
-
Oct 8th, 2006, 02:29 PM
#1
Thread Starter
Lively Member
Possible Syntax Error?
Code:
$query = "SELECT * FROM helpfultips";
$result = mysql_query($query);
$i = 0;
while($row = mysql_fetch_array($result))
{
extract($row);
$tipsy[i] = $tip;
$i++;
}
$tipnum = rand(0, $i);
echo $tipsy[$tipnum];
I have this helpful tips table which has tips to be randomized every time you changed the page. But it won't show the tip! If I put the echo up in the loop it works but then it shows all of the tips, I only want one random one. I don't understand why it won't work, this has never happened to me before. Does anybody see a reason why it wouldn't work?
-
Oct 8th, 2006, 03:03 PM
#2
Re: Possible Syntax Error?
you aren't assigning your array a correct index. you're using i when you should be using $i. only thing I could think of. never used extract() with a query before, so if it still isn't working or if that was just some typo on your part, you can always try using $row['tip'] instead.
-
Oct 8th, 2006, 03:07 PM
#3
Thread Starter
Lively Member
Re: Possible Syntax Error?
Wow, I can't believe I made such a simple mistake. What the hell was I thinking? That was exactly the problem, I am almost embarrassed.... I had a late night last night, but THANK YOU SO MUCH
-
Oct 8th, 2006, 04:56 PM
#4
Re: Possible Syntax Error?
Set your PHP warning level to emit warnings, and even notices. This shouldn't have gone unnoticed. (Pun not intended.)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|