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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:03:48+00:00 2026-06-11T14:03:48+00:00

I am trying to execute multiple update queries at a time. Please have a

  • 0

I am trying to execute multiple update queries at a time. Please have a look into below mentioned code.

Actual code block:

$relist_item_id  = $_REQUEST['relist_item_id'];   // an array
$relist_item_num = count($relist_item_id);

for($j = 0; $j < $relist_item_num; $j++){
  $item_id = $relist_item_id[$j]; 
  $update_query = "UPDATE items SET ActiveItem=1 WHERE id=$item_id";
  mysql_query($update_query);
}

The above code will execute each query one by one. But i want to execute all the query at a time and so i have tried the below code.

$update_query = '';
for($j = 0; $j < $relist_item_num; $j++){
  $item_id = $relist_item_id[$j]; 
  $update_query .= "UPDATE items SET ActiveItem=1 WHERE id=$item_id;";
}
mysql_query($update_query); 

The above mentioned code is not executing/ updating the record. But, i want to execute in similar way. Is it possible to do so?

Using “SQL” in phpmyadmin, i have checked that we can execute more than one query at a time i.e. several update query can be executed at a time. For eg. the below mentioned update query will be executed at a time.

UPDATE items SET ActiveItem=1 WHERE id=1;UPDATE items SET ActiveItem=1 WHERE id=5;UPDATE items SET ActiveItem=1 WHERE id=10;UPDATE items SET ActiveItem=1 WHERE id=12;UPDATE items SET ActiveItem=1 WHERE id=15;UPDATE items SET ActiveItem=1 WHERE id=16;UPDATE items SET ActiveItem=1 WHERE id=20;

I would also like to know that is there any limit on the query like we can execute maximum of 20 queries at a time or so?

My actual target is to save the execution time as there can be a huge for loop and it may take many time to execute each and every query one by one. My above approach may not be correct. But, your idea can help me to do so.

Thanks in advance.

  • 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-11T14:03:49+00:00Added an answer on June 11, 2026 at 2:03 pm

    Why not use an in function like this:

    $relist_item_id  = $_REQUEST['relist_item_id'];   // an array
    $query="UPDATE items 
        SET ActiveItem=1 WHERE id in (".implode(', ', $relist_item_id).")";
    

    Assumes that the values are numeric and don’t need to be encapsed in single quotes.
    If they are, this should work:

    $query="UPDATE items 
        SET ActiveItem=1 WHERE id in ('".implode("', '", $relist_item_id)."')";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I find myself repeating a common pattern when trying to execute code across multiple
In my example code below, you can see that I have been trying to
In the following command i am trying to ssh commands and execute the multiple
Trying to execute powershell script in my C# code. Using .NET Framework v. 4.0.30319
Im trying to execute a .bat file remotely in a powershell script. The code
I`m trying to execute linux commant 'cat' from java code, but it does not
I'm trying to run one SQL command to update multiple databases. If I copy
I was trying to understand why numberOfSectionsInTableView is being called multiple times each time
In my Script Component, am trying to execute Stored Procedure => which return multiple
I am using VS2005 and SQL Server 2005. I am trying to execute multiple

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.