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

  • SEARCH
  • Home
  • 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 4083676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:20:35+00:00 2026-05-20T18:20:35+00:00

How do I get a SQL script to collect all the IDs from a

  • 0

How do I get a SQL script to collect all the IDs from a field and put them in an array?

  • 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-05-20T18:20:36+00:00Added an answer on May 20, 2026 at 6:20 pm

    If we assume that the ID column is just called id, then try the following code (DB connection code ommitted for clarity):

    $ids_array = array();
    
    $result = mysql_query("SELECT id FROM table_name");
    
    while($row = mysql_fetch_array($result))
    {
        $ids_array[] = $row['id'];
    }
    

    If you want to sort the IDs ascending or descending, simply add ORDER BY id ASC or ORDER BY id DESC respectively to the end of the MySQL query

    What the code above does is iterate through every row returned by the query. $row is an array of the current row, which just contains id, because that’s all we’re selecting from the database (SELECT id FROM ...). Using $ids_array[] will add a new element to the end of the array you’re storing your IDs in ($ids_array, and will have the value of $row['id'] (the ID from the current row in the query) put into it.

    After the while loop, use print_r($ids_array); to see what it looks like.

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

Sidebar

Related Questions

I get the following error from the SQL Script I am trying to run:
Is there a way to get all the SQL change script of the object
I'm using powershell script to run a few *.sql file. I can get the
I'm trying to get SQL Server to order by a column from a nested
How can you get the SQL for a Django model's .save(), i.e. from django.db
I get this error when trying to run this Oracle SQL script. Any help
When I write report for SQL Reporting Services I put SQL-script inside my report
I have the below SQL Script which is run from Excel VBA using ADO
When I am trying to execute my sql script by Flyway, I get java.sql.SQLSyntaxErrorException:
We are importing data from .sql script containing UTF-8 encoded data to MySQL database:

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.