I have a table with an integer field that is used to control the custom display order a record.
Example:
SET @rownumber = 0;
SELECT
@rownumber:=@rownumber+1 AS rownumber,
slides.displayorder
WHERE
active = 1
ORDER BY displayorder ASC
This query gives me a result a bit like this:
rownumber | displayorder
-----------+-------------
1 2
2 7
3 15
4 50
5 80
This works OK until a record gets deleted / unapproved (hence the gaps in display order).
What I would like to do is run an update query that sets the displayorder column to the value of the rownumber variable after a record is removed.
Giving a result like this:
rownumber | displayorder
-----------+-------------
1 1
2 2
3 3
4 4
5 5
Is there an easy way to do this?
This seemed to do the job.