Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8836105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:24:53+00:00 2026-06-14T09:24:53+00:00

I have a database MySQL like this: ———————— | id | Name | City

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:24:54+00:00Added an answer on June 14, 2026 at 9:24 am

    Considering that you have already the results fetched as array you can do this:

    for ($i = 1; $i <= count($results); $i++) {
        $n{$i} = $results[$i-1];
    }
    

    the result in this case will be:

    $n1 = array('id' => 3, 'name' => 'Annie'...);
    $n2 = array('id' => 2, 'name' => 'Jim');
    

    or you can do:

    for ($i = 1; $i <= count($results); $i++) {
        $n{$i} = $results[$i-1]['name'];
    }
    

    and in this case the result will be:

    $n1 = 'Annie';
    $n2 = 'Jim';
    

    but the real question is, why not use the results array itself?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mysql database that looks like this: |id | city | created
I have a MySQL database that looks like this: users ( id , name
I have a MySQL Database That Looks like This: Name: Joe Items: 25 CreationDate:
I have mysql database like this id | code 1 | bok-1 2 |
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have multiple tables in a MySQL database. Lets say they look like this:
I have this strings saved in my mysql database in format like: /uploads/attachments/18/105/WordPress_3_Cookbook.pdf Now,
I have a mysql database with a table structure like below : Table Name
I have a code snippet which connects to a MySQL database like this (not
Here is my question : I have a database (mysql) like this : id0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.