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 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

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I am working on a web application that allows users to upload attachments. These
I am creating a Web application using ASP.NET MVC, and I'm trying to use
This is the situation I am facing. I have developed a web application that
I am creating a front-end for a data collection web application. Operators using the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.