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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:50:50+00:00 2026-05-22T12:50:50+00:00

Two simple scenarios: $group_sql = $db->prepare(UPDATE `groups` SET `group`=? WHERE `group_id`=?;); foreach($_POST[‘groups’] as $id

  • 0

Two simple scenarios:

$group_sql  = $db->prepare("UPDATE `groups` SET `group`=? WHERE `group_id`=?;");

foreach($_POST['groups'] as $id => $group)
{
    $group_sql->execute(array($group, $id));
}

And multi-update:

$query      = array();

foreach($_POST['groups'] as $id => $group)
{
    $query[]    = "WHEN {$id} THEN {$db->quote($group)}";
}

$query      = "
UPDATE `groups`
SET `group` = CASE `group_id`
    " . implode("\r\n", $query) . "
END
WHERE `group_id` IN (" . implode(',', array_keys($_POST['groups'])) . ");
";

Which will eventually generate:

UPDATE `groups`
SET `group` = CASE `group_id`
    WHEN 3054 THEN 'moteris savo vaikams'
    WHEN 3055 THEN 'bičių šeimoje'
END
WHERE `group_id` IN (3054,3055)

Which one is better to use?

UPDATE

Since I noticed that people are not familiar with such method, I’ve decided to expand the example to use multiple column/row update.

UPDATE `groups`
    SET `group` = CASE `group_id`
        WHEN 3054 THEN 'moteris savo vaikams'
        WHEN 3055 THEN 'bičių šeimoje'
    END,
    SET `description` = CASE `group_id`
        WHEN 3054 THEN 'foo'
        WHEN 3055 THEN 'bar'
    END
    WHERE `group_id` IN (3054,3055)
  • 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-22T12:50:51+00:00Added an answer on May 22, 2026 at 12:50 pm

    It depends entirely on your table and index structure. If group_id is index so that it can look it up directly, without scanning an index or a table it should yield similar performance.

    If it isn’t indexed the last form should be able to handle with one index/table scan instead of two, which will get better performance.

    Interesting idea to handle multiupdates that way, haven’t seen it before.

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

Sidebar

Related Questions

I have a simple scenario, where two servers are connected through a gigabit link.
Ok, i have simple scenario: have two pages: login and welcome pages. im using
I have two simple tables in my database. A card table that contains Id,
I have two simple while loops in my program that I feel ought to
I need to be able to merge two (very simple) JavaScript objects at runtime.
Simple idea: I have two images that I want to merge, one is 500x500
I have a really simple class with two methods; One that will be called
I have a simple database with two tables. Users and Configurations. A user has
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have
Does anyone know of a simple way to compare two strings together to generate

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.