SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Perpetual While() Loop -- Why?

    Would someone please enlighten me as to the reason why this while() loop continues forever? Should it not end when all of the forums have been selected from the forums table in the first queries before the loop? What happens is the all of the forums are returned and then the last forum to be returned is looped indefinitely. Your help is very much appreciated:
    PHP Code:
    <?php
    $contenttitle
    ="T-O District Forums";
    include(
    "header.php");
    include(
    "functionlib.php");
    connect_db();
    $query=@mysql_query("SELECT id, name, description ".
        
    "FROM forums ORDER BY orderby")
            or exit(
    "<p>An error was encountered: ".mysql_error().".</p>\n");
    echo(
    "<table width=\"650\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n".
        
    "<td width=\"170\" align=\"left\" valign=\"top\">\n".
        
    "<p>Forum</p></td>\n".
        
    "<td width=\"270\" align=\"left\" valign=\"top\">\n".
        
    "<p>Description</p></td>\n".
        
    "<td width=\"70\" align=\"center\" valign=\"top\">\n".
        
    "<p>Threads</p></td>\n".
        
    "<td width=\"70\" align=\"center\" valign=\"top\">\n".
        
    "<p>Posts</p></td>\n".
        
    "<td width=\"70\" align=\"center\" valign=\"top\">\n".
        
    "<p>Last Post</p></td>\n</tr>\n");
    while(
    $result=mysql_fetch_array($query))
    {
        
    $sub_query=@mysql_query("SELECT COUNT(*) AS thread_count ".
            
    "FROM threads, forums, thread_lookup ".
            
    "WHERE forums.id=thread_lookup.fid ".
            
    "AND threads.id=thread_lookup.tid")
                or exit(
    "<p>An error was encountered: ".mysql_error().".</p>\n");
        
    $sub_result=mysql_result($query,0);
        echo(
    "<tr>\n<td width=\"170\" align=\"left\" valign=\"top\">\n".
            
    "<p><a href=\"forums.php?forumid=".$result['id']."\">".$result['name']."</a></p>\n</td>\n".
            
    "<td width=\"270\" align=\"left\" valign=\"top\">\n".
            
    "<p>".$result['description']."</p>\n</td>\n".
            
    "<td width=\"70\" align=\"center\" valign=\"top\">\n".
            
    "<p>".$sub_result['thread_count']."</p>\n</td>\n".
            
    "<td width=\"70\" align=\"center\" valign=\"top\">\n".
            
    "<p>&nbsp;</p>\n</td>\n".
            
    "<td width=\"70\" align=\"center\" valign=\"top\">\n".
            
    "<p>Last Post</p>\n</td>\n</tr>\n");
    }
    echo(
    "</table>\n");
    include(
    "footer_no_sidebar.php");
    ?>


    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nevermind -- I found the source of the problem.

    Why the solution eludes me until after I post, I don't know.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


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
  •