SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Infinite Loop

  1. #1
    SitePoint Zealot JordanTLClive's Avatar
    Join Date
    Feb 2001
    Location
    Las Vegas, NV
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im trying to write a news script that retrieves information from the database based on the query string and returns the news stories that match. Because there may be more than one story for each query... I use a while loop to display the different stories. I am not sure why but it is an infinite loop. The code can be viewed at http://www.hotmusicstars.com/php/news.txt and the page can be loaded at http://www.hotmusicstars.com/php/news.php/author/Jordan

    Can anyone tell me how to fix this to stop the infinite looping?
    -Jordan

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Zealot JordanTLClive's Avatar
    Join Date
    Feb 2001
    Location
    Las Vegas, NV
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it should work now.
    -Jordan

  4. #4
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this between : include("$headerpath"); and include("$footerpath");


    Code:
    $result = mysql_query($querys);
    $number = mysql_numrows($result);
    
    $i = 0;
    
    while ($number > $i && $results = mysql_fetch_array($querys)) {
    
                 $headline = $results["headline"];
    	$news = $results["newstext"];
    	$date = $results["newsdate"];
    	$aqu = mysql_query("SELECT name, email FROM authors WHERE id=news.aid");
    	$aqua = mysql_fetch_array($aqu);
    	$name = $aqua["name"];
    	$email = $aqua["email"];
    
    PRINT "
    
    <!-- Main Content Begin -->
    
    <table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#B08820\">
     <tr> 
      <td bgcolor=\"#B08820\">
       <div align=\"center\"><b><font face=\"Verdana\" size=\"1\" color=\"#000060\">:: $headline ::
    </font></b></div></td>
      </td>
     </tr>
     <tr> 
      <td> 
    <b>Last Updated: $date </b><br>
     $news <br>
    -<a href=\"mailto:$email\">$name</a>
     </td>
     </tr>
    </table><br>
    <!-- Main Content End -->
    
    ";
    
    $i++;
    
    }
    . . . chris

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Firstly, on line 57 you have:
    PHP Code:
    $querys mysql_query("SELECT * FROM news WHERE$quend"); 
    I've got a feeling that (if $quend is non-zero) this is going to return the entire table. You want something like
    PHP Code:
    $querys mysql_query("SELECT * FROM news WHERE column_name = $quend"); 
    Assuming that $quend is a numeric value (else wrap it in single quotes for a string).

    Secondly, I don't think you are getting an infinite loop. It just seems like it because (1 - you are working with the entire table; 2 - you are grinding down php with the following recursive error):

    Line 73:
    PHP Code:
        $aqu mysql_query("SELECT name, email FROM authors WHERE id=news.aid"); 
    What is news.aid ? What are you trying to do here?

    Thirdly, I don't really know about this, but, I am suspicious that creating a new table for each record might be burdening the web browser. It might be easier on the browser if you were to have one large table and just add rows in the while loop ???


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
  •