I’m not even sure if this is quite possible to do with MySQL, but I hope it is.
OK so i have this SQL command
SELECT * FROM table WHERE $WhereCondition ORDER BY ListStyle
As an example of the data in the ListStyle I might have
2000 3000 3700 3800
What I’m hoping to do is use some kind of if statement in the SQL that will allow me to check other fields in a result row so that I can change the value of the ListStyle before I use that in the page to order it appropriately.
So for instance I have fields a, b and c. Now if a and b are NOT empty and c = 100 and the ListStyle = 3700, I want to change the value of ListStyle to 3699 so that when I print out a result loop, rows that match the condition ( a != '', b != '', c = 100 and ListStyle = 3700) will then be shown above the rows that have the ListStyle of 3700
I can’t simply edit the data in the database, even though that would be an easy solution. The data has to stay as it is.
I originally tried doing this in php. While its easy enough to change the value of the ListStyle using if statements, I don’t know of an easy way to then actually order my results without sticking everything into an array and then sorting through it. I really don’t want to do that as it would mean re-writing a lot of code, which is why I’m hoping this is all possible to do in MySQL.
Can anyone help with this?
try something like: