StringDot
StringDot

Reputation: 27

Allowed memory size of 134217728 bytes exhausted

What i do wrong in this code? i tried to solve with "ini_set('memory_limit', '-1');" but didn't work. I think that my while is infinite loop. My column post have just 6 rows.

<?php
$user = $_SESSION['login_username'];
$db = mysqli_connect("localhost","stringdot","Ninja123","ddbase"); 
$query = "SELECT post FROM posts WHERE username = '$user' ORDER BY date_post DESC";
$result = mysqli_query($db,$query);
$result = mysqli_fetch_assoc($result);
$posts = array();

while($row = $result) {
    $posts = $row['post'];
}

print_r ($posts);

?>    

Upvotes: 0

Views: 234

Answers (1)

The problem is born here

while($row = $result) {

the condition $row = $result is an assignment

This assignment will always be true as it can put $result in $row

instead mysql_fetch_array($result) Each loop takes the next value, if the assignment is not successful

You can resolve it with this

while($row = mysql_fetch_array($result)) {
    $posts = $row['post'];
}

Upvotes: 2

Related Questions