Page 1 of 1

Memory leak?

Posted: Wed Aug 11, 2004 1:00 pm
by pinehead18

Code: Select all

<?php
<?php
db_connect('lkcforum'); 


        $sql = "SELECT name FROM forums WHERE forum_id='{$_GET['f']}'"; 
        $result = mysql_query($sql,$con) or die(mysql_error()); 
        $row = mysql_fetch_array($result); 
                $forum_name = $row['name']; 


       $sql = "SELECT subject,author,tid,forum_id FROM topics WHERE forum_id='{$_GET['f']}'"; 
       $result = mysql_query($sql,$con) or die(mysql_error()); 
       while ($row = mysql_fetch_array($result)) { 

                $subject = $row['subject']; 
                $topic_id = $row['tid']; 
                $author = $row['author']; 
                $forum_id = $row['forum_id']; 

        $sql = "SELECT date FROM threads WHERE tid='$topic_id'"; 
        $result = mysql_query($sql); 
        $row = mysql_fetch_array($result); 
                $date = $row['date']; 


        if (strlen($subject) > 42) { 
                        $filler = "..."; 
                        $subject = substr($subject, 0, 42 - $filler) . $filler; 
                } 

               $topics .= " 
                        <tr> 
                               <td width=60%><a href=viewtopic.php?tid=".$topic_id."&fid=$forum_id>$subject</a></td> 
                               <td width=20% align=center><a href=/myprofile/$author>$author</a></td> 
                               <td width=20%>$date</td> 
                           </tr>"; 


        }
?> 
?>
That is my entire code when i add the following code (which is above as well) i get an exhausted memory error

Code: Select all

<?php
 $sql = "SELECT date FROM threads WHERE tid='$topic_id'";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);
                $date = $row['date'];
?>

Posted: Wed Aug 11, 2004 1:06 pm
by feyd
try freeing the results of that query after you've used it.. otherwise, it's probably staying resident in memory..

Posted: Wed Aug 11, 2004 1:21 pm
by pinehead18
What do you mean by freeing the results?

Posted: Wed Aug 11, 2004 1:39 pm
by feyd
your third query is being repeated over and over, this stores more and more results in memory until the page ends. You need to either alter your second query to fetch the date from that table, or you need to free the results of the third query after you've pulled the information and before the loop starts again.. [php_man]mysql_free_result[/php_man]()