Good night. There is such a table

num | id 2 | 5435 3 | 785 1 | 964 

How to select id by sorting num and output each id to different variables, for example $ id1, $ id2, $ id3 (of course, via PDO)?

  • Why the variables $id1 $id2 $id3 , in not an array? What caused this strange behavior? And if in the table there are 1000000 lines? - Alexey Shimansky
  • It is possible in the array but the main thing is to write by sorting num in descending or increasing order. Anyway, from the array I will distribute the variables. - TheAs110z

1 answer 1

The task, as written in the comments - is the lishin of all logic .. well, okay)

 $a = $log->db->query("SELECT `id` FROM `logs` WHERE 1 ORDER BY `num` DESC")->fetchAll(PDO::FETCH_COLUMN); foreach ($a as $aa){ $var_name="id$aa"; $$var_name=$aa; } print_r($a); /* Array ( [0] => 9459871 [1] => 9459872 [2] => 9459873 ) */ echo $id9459871; // вернет 9459871