$get_names = mysql_query("SELECT `name` FROM `users`"); // ВЫВОДИМ СПИСОК ИМЁН while($name = mysql_fetch_row($get_names)) { if(isset($name[0])) { echo $name[0]."<br>"; // выводит имена пользователей } } // ВЫВОДИМ СПИСОК ИМЁН ЕЩЁ РАЗ while($name = mysql_fetch_row($get_names)) { if(isset($name[0])) { echo $name[0]."<br>"; // здесь ничего не выводится.. } } 

Why the data is not displayed in the second cycle?

  • 2
    Well, you have all the records output, they are no longer there, and mysql_fetch_row just gets the next record, not the past ones. To reset the record pointer in your case, you must use mysql_data_seek . Then you will again be at the top of the list and will be able to use mysql_fetch_row again - BOPOH
  • Yes, I thought that it was in the internal index. Thank you. - StasHappy
  • The mysql_ is outdated, you need to get rid of it (at least replace it with mysqli ). And the approach with rewinding results is dubious. It is better to get a set of records, and then use it already - BOPOH
  • @stashappy, mysql_ functions mysql_* DECLINED !!! Use at least mysqli_* functions. - Visman pm
  • Buddy, I understood, understood. Why so loud ... - StasHappy

1 answer 1

because you have already done fetch and no more data from the cursor

try this

 $get_names = mysql_query("SELECT `name` FROM `users`"); // ВЫВОДИМ СПИСОК ИМЁН $k=0; while($name[$k] = mysql_fetch_row($get_names)) { if(isset($name[$k][0])) { echo $name[$k][0]."<br>"; // выводит имена пользователей } $k++; } // ВЫВОДИМ СПИСОК ИМЁН ЕЩЁ РАЗ $k=0; while(isset($name[$k])) { if(isset($name[$k][0])) { echo $name[$k][0]."<br>"; // здесь ничего не выводится.. } $k++; } 

There are other methods, but I wrote the most unchanged code.