Results 1 to 4 of 4

Thread: Possible Syntax Error?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    110

    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?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    110

    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

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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
  •  



Click Here to Expand Forum to Full Width