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 6852421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:22:06+00:00 2026-05-27T01:22:06+00:00

I have an array which contains numbers like 331,554,22 or it could be 45,

  • 0

I have an array which contains numbers like “331,554,22” or it could be “45”, lets say the array is called $numbers.

I want to loop through the array and for each number or entry in it, do a SQL query like

UPDATE members SET x=1 where id=$numbers[x]

Could someone help me along?

UPDATE: Also, say I store the query values in a text field in my database called nums and it looks like eg. “45,656,23”, how would I convert that to an array format?

  • 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-27T01:22:07+00:00Added an answer on May 27, 2026 at 1:22 am

    if the veriable "331,554,22" is not an array (string),
    explode it first

    $numbers = explode(',',$numbers);
    

    and then.

    Foreach :

     foreach ($numbers as $number)
            {
              //query like  SET x=1 where id=$number
            }
    

    For :

        for($i = 0; $i < count($numbers); $i++)
        {
           //query like  SET x=1 where id=$numbers[$i]
        }
    

    if x is always 1 you can use in,

    $query = "UPDATE table SET x = 1 WHERE id  IN(" . implode(',',$numbers)  . ")"
    

    and if the $numbers variable is string, and x will be 1 for each ID, forget all of I wrote and try this only 🙂

    $query = "UPDATE table SET x = 1 WHERE id  IN({$numbers})"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an array which could look like this: $config[$name][$array]['key'] = 'value'; // here
I have a string like abcdefg123hijklm . I also have an array which contains
I have an array which contains 2 types of items (lets call them type
i have an array which contains only 2 types of numbers(x and x-1) eg:-
I have array like this: array('1224*', '543*', '321*' ...) which contains about 17,00 "masks"
I have an array which contains the following numbers: 10000 900 670 600 500
I have an array which contains another array Would I notate it this way?
I have an array which contains around 50-200 hyperlinks. How can I pass this
Am I missing something in the Array documentation? I have an array which contains
I have an array DetailsArray in VB.NET which contains the result of a LINQ

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.