I have a database MySQL like this:
------------------------
| id | Name | City |
------------------------
| 1 | John | London |
| 2 | Jim | N.York |
| 3 | Annie | Rome |
By the following query I retrieve the last n data of a specific column:
SELECT id, Name, City FROM mytable ORDER by id DESC limit
0,2
in this case I retrieve the last two records from the columns “id” , “Name” and “City”
How can i associate a specific variable in php to each name of my result?
For example:
$n1 = Annie
$n2 = Jim
So i’ll be able to use each single element of the resulting query for my needs in the following part of my php code?
Thanks.
Considering that you have already the results fetched as array you can do this:
the result in this case will be:
or you can do:
and in this case the result will be:
but the real question is, why not use the results array itself?