D
D
Denis99992018-03-18 17:16:58
PHP
Denis9999, 2018-03-18 17:16:58

Simple sql query not returning all records?

The code is the following:

$query2 ='SELECT pid, title, filename FROM photos WHERE pid=' . $row['id'];
$result2 = mysqli_query($link, $query2);
$row2 = mysqli_fetch_array($result2);
while( $row2 = mysqli_fetch_assoc($result2) ){ 
  echo '    query2 - '.$row2['pid'] . ' '.$row2['filename'] . '<br>';
}

Outputs:
query2 - 170 5101_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
query2 - 170 5102_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
query2 - 170 5103_chempionat-tsentralnogo_federalnogo-okruga-rossii.jpg 170sentralnogo
query2 - 170sentralnogo-federalnogo-okruga-rossii.jpg -federalnogo-okruga-rossii.jpg
query2 - 170 5105_chempionat-tsentralnogo-federalnogo-okruga
-rossii.jpg
query2 - 170 5106_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
query2 - 170 5108_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
query2 - 170 5109_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
query2 - 170 5110_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
query2 - 170 5111_chempionat-tsentralnogo-federalnogo-
okruga
-rossii.jpg -okruga-rossii.jpg
query2 - 170 5114_chempionat-tsentralnogo-federalnogo-okruga-
rossii.jpg
query2 - 170 5115_chempionat-tsentralnogo-federalnogo-okruga-rossii.jpg
The problem is that there is always one entry missing. In phpmyadmin I made a similar request - it displays all records. And as a result of this request, a record is visible that is missing when executed by the above code, it is clear that its pid is the same as the rest.
Why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maddog670, 2018-03-18
@Denis9999

And you are not confused by 2 mysql_fetch?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question