Infinite Loop?

Discussion in 'PHP' started by . Jordan ., Sep 8, 2010.

  1. #1
    So I keep getting the error...

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 35 bytes) in /home/jordana/public_html/work/php/pagination/index.php on line 50
    Code (markup):
    Which to my knowledge is cause by a infinate loop. However from what I see the loop should be fine. Can anyone see anything wrong with this?

    $numRows = $allMsgs->num_rows;
    $numPages = round($numRows/10);
    $pageStarts = array();
    
    for($i = 0; $i <= ($numPages + 1); $i+10) {
    	
    	array_push($pageStarts, $i);
    	if($i==0) {
    		$i++;
    	} else {
    		
    	}
    	
    }
    PHP:

     
    . Jordan ., Sep 8, 2010 IP
  2. Eager2Seo

    Eager2Seo Member

    Messages:
    72
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #2
    change the for loop increment to:
    $i+=10
    Code (markup):
    also, how many items are in numpages?
     
    Eager2Seo, Sep 8, 2010 IP
  3. . Jordan .

    . Jordan . Guest

    Messages:
    51
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. That fixed it :)

    numPages is just an integer which says how many pages need to be made based on the number of rows and rows per page.
     
    . Jordan ., Sep 8, 2010 IP
  4. Eager2Seo

    Eager2Seo Member

    Messages:
    72
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #4
    Its also bad programming practice to modify a for counter in your loop. Practice good coding habits, and make your life easier! If you need to start at 1, just initialize the counter that way.
     
    Eager2Seo, Sep 8, 2010 IP