Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts

    phpbb mysql While loop not looping

    I'm trying to create a portal for phpbb3 and the code below only loops once so I only get one post (yes there is actually more in the db)

    PHP Code:
    if ($user->data['is_registered'])

        
    $sql "SELECT post_username, post_subject, forum_id, post_id FROM phpbb_posts ";
        
    $result $db->sql_query($sql);

       while ( (
    $row $db->sql_fetchrow($result)) && ($row['post_subject'] != ''))
        {
            if (
    $row['forum_id'] == || $auth->acl_get('f_read'$row['forum_id']))
            {
            
    $template->assign_block_vars('new_posts', array(
            
    'FULL_TITLE'    => $row['post_subject'],
            
    'FORUM'        => $row['forum_id'],
            
    'POSTER_NAME'    => $row['post_username'],
            
    'U_VIEW_TOPIC'    => append_sid("{$phpbb_root_path}viewtopic.$phpEx"'f=' $row['forum_id'] . '&p=' $row['post_id'] ),
                            )
                        );
            }
        
    $db->sql_freeresult($result);


        } 
    the relevant template code is here
    Code:
    	
    
    	<!-- BEGIN new_posts -->
    		<a href="{new_posts.U_VIEW_TOPIC}" title="{new_posts.FULL_TITLE}">{new_posts.FULL_TITLE}  by  {POSTER_NAME}</a><br />
    		<!-- END new_posts -->
    any pointer anybody I've looked at all the similar code I can find and I just can't work this out
    Last edited by psykx; 11-07-2007 at 07:20 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Are the post_subject column values empty? Because that's the 2nd part of the "while" loop comparison operator... the first post encountered with an empty post_subject will abort the loop.

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    No the post_subject is always filled.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,037
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Ummm. You are apparently (it is a bit hard to find the correct ending ")" due to the numerous ones floating around) freeing up the result resource inside of the while() loop. After the first time, there is no result resource and the while() loop condition is false. The following line of code should be after the end of the while() loop -
    PHP Code:
    $db->sql_freeresult($result); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    psykx (11-07-2007)

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    89
    Thanks
    1
    Thanked 2 Times in 2 Posts
    that was it! perfect thanks very much

    I spent a whole day (8+ hours) scratching my head at that one _and_ I rewrote the code three times. I can't believe I missed it


  •  

    Posting Permissions

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