I wish to simply display something utilizing a while loop with php, but it's no longer working.

This is actually the code -

<?php 

mysqli_select_db($connect,"users");

$select_title = "select title, message from messages where user = '$u' LIMIT 4 ";

$querying = mysqli_query($connect,$select_title) or die ('Whops! Something went wrong.');

$line = mysqli_fetch_assoc($querying);

    //$title = mysqli_real_escape_string($connect,trim($line['title']));

while(($rows = mysqli_fetch_assoc($querying)))
{

    echo $rows['title'];
}

?>

Now I've two game titles, only the first is being displayed. Why so?

You've fetched one row here:

$line = mysqli_fetch_assoc($querying);

The cursor is going to be moved to another row, hence

while(($rows = mysqli_fetch_assoc($querying)))
{

    echo $rows['title'];
}

displays the 2nd row only.

The very best option would be simply comment that line:

 //$line = mysqli_fetch_assoc($querying);

Remove this line:

$line = mysqli_fetch_assoc($querying);

Comment this line will solve your condition

//$line = mysqli_fetch_assoc($querying);

... since you fetch the very first title using the line $line = mysqli_fetch_assoc($querying); but never echo it after which begin a loop to undergo the relaxation from the game titles.

Remove/uncomment the road and you ought to be fine.

you already fetch one record with

$line = mysqli_fetch_assoc($querying);

so there's just one left all the while

Debug

My MySQL is a little rusty(Very long time ago since i have used SQL => Gone to live in NoSQL camping...), but this is exactly what I'd do:

  • First I'd test if query returns correct result using phpmyadmin console or simply mysql console from commandline.

However I guess the totally correct because many people say that

$line = mysqli_fetch_assoc($querying);

has already been fetching a row. But nonetheless you could utilize it for debugging reasons I suppose.

PDO

Also I must explain you need to PDO rather than mysqli(almost deprecated I suppose). PDO prepared claims also safeguard you from SQL-injections and may be faster since it is precompiled.

Any time you call mysqli_fetch_assoc() you "take" one record in the result set. When you will find forget about records, mysqli_fetch_assoc() returns false. This really is, incidentally, the main reason you should use while loop.

Whenever you known as $line = mysqli_fetch_assoc($querying);, you required one record in the result set, departing only one within the result set. So that your while loop iterates over that one record only. As everybody else stated - you need to simply comment that line.

I'm also able to recommend using mysqli_fetch_all() function, this provides you with an regular array which you can use, well, just like a normal array

$results = mysqli_fetch_all($querying, MYSQLI_ASSOC);