Are there alternative approaches to sorting and reordering data in a SQL table without directly manipulating IDs in PHP?

When sorting and reordering data in a SQL table, it is common to use the ORDER BY clause in SQL queries to retrieve data in a specific order. However, if you want to change the order of data without directly manipulating IDs in PHP, one alternative approach is to add a separate column in the table to store the order information. This column can be used to determine the order in which the data should be displayed.

// Example of adding a new column "order_number" to the table to store the order information
$addOrderColumnQuery = "ALTER TABLE table_name ADD COLUMN order_number INT DEFAULT 0";

// Update the order information for specific rows
$updateOrderQuery = "UPDATE table_name SET order_number = CASE 
                        WHEN id = 1 THEN 1
                        WHEN id = 2 THEN 2
                        WHEN id = 3 THEN 3
                        ELSE 0 END";

// Retrieve data from the table in the desired order
$getDataQuery = "SELECT * FROM table_name ORDER BY order_number ASC";