limit mysql weirdness

When executing a request

<?php
require_once "conf.php";
dbConnect();
$zapros1=mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
$rez=mysql_fetch_array($zapros1);
while ($rez=mysql_fetch_array($zapros1)){
echo ($rez['id']);
}

?>

For some reason, it returns four elements, and not 5. What should I do?


Answer 1, authority 100%

Try this

<?php
require_once "conf.php";
dbConnect();
$zapros1=mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 0,5");
while ($rez=mysql_fetch_assoc($zapros1)){
echo ($rez['id']);
}
?>

Answer 2, authority 25%

Set LIMIT 0,5
added — compare LIMIT 0.5 and LIMIT 1.5 if the first gives 4 news and the second 5 news, then we look at the database and delete the last line – it is empty


Answer 3, authority 25%

<?php
require_once "conf.php";
dbConnect();
$zapros1=mysql_query("SELECT * FROM news ORDER BY id DESC LIMIT 5");
$rez=mysql_fetch_array($zapros1);  // sdesi vibiraetsea pervaia stroca
while ($rez=mysql_fetch_array($zapros1)){ // v tsikle vivodeatsea ostavshiesea 4..
echo ($rez['id']);
}
?>

Just remove the line

from the code

$rez=mysql_fetch_array($zapros1);

Answer 4

It is quite possible that there are not enough records in the database.