PDA

Click to See Complete Forum and Search --> : Possible Syntax Error?


ChR0NiC
Oct 8th, 2006, 02:29 PM
$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?

kows
Oct 8th, 2006, 03:03 PM
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.

ChR0NiC
Oct 8th, 2006, 03:07 PM
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

CornedBee
Oct 8th, 2006, 04:56 PM
Set your PHP warning level to emit warnings, and even notices. This shouldn't have gone unnoticed. (Pun not intended.)