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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:42:46+00:00 2026-05-11T05:42:46+00:00

I am creating a web application that acts as a priority list, allowing a

  • 0

I am creating a web application that acts as a priority list, allowing a user to re-arrange a set of items in a list and storing that arrangement in a MySQL database via a PHP backend.

At the moment, when the user has finished arranging their items and saves the configuration, I am calling a seperate UPDATE statement for every row, plugging in the priorityLevel (position in the list) for each.

For example: (not my production code, but this illustrates the point)

<?php   $items = array(12, 17, 27, 26, 5); // an array of IDs, in proper order   // due to nature of foreach loop in PHP, this makes $order be the key value,   // in this case, 0, 1, 2, 3, 4 respectively   foreach ($items as $order => $item)   {     $database->query('UPDATE `table` SET `priorityLevel` = {$order} ' .                      'WHERE `ID` = {$item}');   } ?> 

This works well enough, but it seems inefficient to run so many UPDATE queries, especially when the list gets long and we’re re-ordering many items. I was hoping there was some way to dynamically create the order within the UPDATE command, something like this:

<?php   $database->query('UPDATE `table` SET `priorityLevel` = ORDER_NUMBER ' .                    'WHERE `ID` IN (12, 17, 27, 26, 5)'); ?> 

… where ORDER_NUMBER was a dynamic number determined perhaps by the position of the ID value in the WHERE clause. It would need to respect the order of the items in the WHERE clause as well to make sure the priorityLevel was set according to the user’s wishes.

Does anyone know if this is possible in a MySQL 5 / PHP 5 environment? The table is using the MyISAM engine so it does not support transactions.

(PS – I know some of the basics of MySQL well enough, but I am far from an expert, so if there is anything involved here beyond simple CREATE,INSERT,UPDATE,DELETE commands, please be descriptive)

(PPS – This subject is hard to Google, as the terms are too generic. If I search for ‘mysql order’, I get a bunch of tutorials on creating Shopping Cart applications for MySQL!)

  • 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. 2026-05-11T05:42:46+00:00Added an answer on May 11, 2026 at 5:42 am

    You have to build a query in PHP like this and send that query to mysql:

    UPDATE `table` SET priorityLevel =  CASE  WHEN `ID` = 12 THEN 1 WHEN `ID` = 17 THEN 2  WHEN `ID` = 27 THEN 3 WHEN `ID` = 26 THEN 4 WHEN `ID` = 5 THEN 5 END  WHERE `ID` IN (12, 17, 27, 26, 5);

    (Tested with MySql 5.0)

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

Sidebar

Related Questions

For a web application, when creating the user which will connect to the MySQL
I'm creating a small application on an embedded device that has a boa web
When creating a web application, and lets say you have a User object denoting
I'm creating a web application for work where the user has to enter the
I am part of a team creating a web application using PHP and MySQL.
I am part of a team creating a web application using PHP and MySQL.
When I'm creating a user for my web application, an SMTP email (using ASP.NET's
When creating a web application that some how displays the display of a unique
I'm creating a web application that will involve habitual file uploading and retrieval (PDFs,
I am creating a web application that is accessing a SQLite database in the

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.