Click here to Skip to main content
15,037,420 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to order my table with a session variable, the session variable is retrieved and i want to display the tables that are only selected by the user, for eg, the user chooses the number 2 and i want to display only dayIDs with the number "2" in the table

What I have tried:

$day= $_SESSION["dayID"];
SELECT dayID
            FROM
            week
            ORDER BY dayID DESC
            AND
            day.dayID= $day  ";
Posted
Updated 23-May-21 22:07pm
v2

1 solution

SQL
SELECT dayID
FROM week
ORDER BY CASE WHEN dayID = @dayID THEN 0 ELSE 1 END, dayID;
But don't use string iterpolation to pass the variable from PHP to your SQL query; that will leave your code vulnerable to SQL Injection[^]. Use a parameterised query instead.

PHP: SQL Injection - Manual[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900