SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Scary's On The Wall
    Join Date
    Apr 2003
    Location
    PA
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick Question: "False" assignments

    PHP Code:
    while ( $category_array[] = $db->sql_fetchrow($result) ); 
    I think you all can pretty much figure out what this is.

    Why is it that when $db->sql_fetchrow() returns FALSE, it is stored in my category array? Shouldn't it stop when it returns false?

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, php is doing exactly what you ask:
    evaluate $db->sql_fetchrow($result)
    store the result as the last element of $category_array
    check that same value, if false (or null or empty string or 0) continue on past the while loop
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It stops when the whole expression $category_array[] = $db->sql_fetchrow($result) evaluates to false; by this time false has already been added to your array.

    Douglas
    Hello World

  4. #4
    Scary's On The Wall
    Join Date
    Apr 2003
    Location
    PA
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah... okay. Darn, thats a doosey.

  5. #5
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wasn't there a thread a while back about some of the time travel functions in PHP? Perhaps one of these could be used to alter the execution of the script between the fetch and the assignment.
    Christopher

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to a more appropriate forum. See Where should I post my thread? for details

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just change it to:
    PHP Code:
    while($row=$db->sql_fetchrow($result))
        
    $catergory_array[]=$row


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •