PHP while loop not showing first item?

loops, mysql, php, while-loop

Solution

`mysql_fetch_array` is used to return a row of the array at each iteration of the while loop.

The extra `mysql_fetch_array` takes the first row into post, and in the first iteration of the while loop it puts the second row into the post.

This is what you should be doing.

$latestVideos = mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 5")or die(mysql_error());

 while($posts = mysql_fetch_array($latestVideos)){
 //do stuff here
 }

Problem

I'm just trying to show a basic list or items from my database but for some reason its not showing the first item so if there is only one thing in a category it doesn't show anything but if there's 2 it will show one item. I've added the code below. query ``` //this query will fetch 4 records only! $latestVideos = mysql_query("SELECT * FROM table ORDER BY date DESC LIMIT 5")or die(mysql_error()); $posts = mysql_fetch_array($latestVideos); ``` While loop ``` while($posts = mysql_fetch_array($latestVideos)){ $dateFormat= $posts['video_date']; $newDate=date('d-m-Y',strtotime($dateFormat)); echo $posts['video_title'] echo $newDate; echo $posts['video_embed']; } ```

Original source