SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    Awesome Addict
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why won't this While Loop terminate?

    I suppose the title of the thread says it all. Am I missing something here??

    PHP Code:
    function getTop10($connection) {
        
    $sql "SELECT DISTINCT(track_page) FROM site_stats ORDER BY track_page DESC LIMIT 1, 10";
        if(!
    $result mysql_query($sql,$connection)) {
            echo 
    "Error 002: Top 10 Pages are unavailable at this time";
        } else {
            
    $topPages mysql_fetch_array($result);
            
    $i 1;                
            while(
    $i 11) {    
                echo 
    $topPages['track_page'] . "<br />\n";
            }                                                                                    
        }
    //end else                        
    //end function 

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are not incrementing $i inside the loop. You set it at 1 and never change it.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $i never changes in value... it always has the value of one.

    Try this:
    PHP Code:
    while($i 11) {     
                 echo 
    $topPages['track_page'] . "<br />\n";
                  
    $i++;
              } 
    </font></font>
    The Banana Stand - an Arrested Development fansite
    LC-3 Help - tutorials on the LC-3 educational assembly language

  4. #4
    SitePoint Enthusiast shref's Avatar
    Join Date
    Nov 2004
    Location
    Egypt, Alexandria
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you forgot something

    PHP Code:
    while($i 11) {     
                echo 
    $topPages['track_page'] . "<br />\n"
             
    $i++ ;
            } 
    Shreef
    blog: shreef.com
    twitter: @shreef

  5. #5
    Awesome Addict
    Join Date
    Mar 2004
    Location
    Toronto, Canada
    Posts
    326
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys ... it's 42 celcius in Toronto today ... heat must be getting to me.


  6. #6
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Be careful. What happens if your query returns less than 10 rows? Would you not be better using the following type of thing?

    while ($row = mysql_fetch_array($result))
    {
    ...
    }

  7. #7
    SitePoint Enthusiast shref's Avatar
    Join Date
    Nov 2004
    Location
    Egypt, Alexandria
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe, you are lucky three answers in one minute
    Shreef
    blog: shreef.com
    twitter: @shreef


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
  •