It is necessary to pull out a number of values ​​from the base. But in the beginning you need only the first, and then the whole set. I use the following code

$photoQwerry = mysql_query("SELECT PhotoPath FROM Photos WHERE ID=$id"); //берем первое значение из массива if($photoQwerry){ echo mysql_result($photoQwerry,0,'PhotoPath'); } ... //выводим весь массив if($photoQwerry){ while($photo = mysql_fetch_array($photoQwerry)){ echo "$photo[PhotoPath]"; } } 

Code simplified and removed too much, but the point in the output of images. The trouble is that the first query "eats" the first value and in the second output all data is output, except for the first line. How to fix it?

    2 answers 2

    You can use the mysql_data_seek() function by calling it after mysql_result() , which moves the cursor to the beginning of the resulting table. Then mysql_fetch_array() will start reading from the first entry.

    PS It should be borne in mind that the mysql extension is outdated and excluded from PHP 7. It is better to focus on mysqli or PDO.

    • Thanks, helped - Zhenya Vedenin

    As an option:

     $photoQwerry = mysql_query("SELECT PhotoPath FROM Photos WHERE ID=$id"); if($photoQwerry){ $isFirstRow = true; while($photo = mysql_fetch_array($photoQwerry)) { if ($isFirstRow) { echo mysql_result($photoQwerry,0,'PhotoPath'); $isFirstRow = false; } echo "$photo[PhotoPath]"; } } 

    PS Just why would you not use the data from mysql_fetch_array for the first line?

    • Just between the first and second part there is another code. You can of course register everything at the end, approximately in the way you wrote, but then you have to write a piece of js code so that it adds the result to the top of the page (( Zhenya Vedenin
    • Or did I not understand something in your version? - Zhenya Vedenin
    • Then you'd better use the @cheops option - via mysql_data_seek - AK
    • Simply, you apparently do not use smarty type template engines - in an amicable way, you need to separate read operations from the database and page output based on the template. - AK
    • Thank, I will consider) - Zhenya Vedenin