Hi All,
Is there any way to parse a MySQL table and incrementally set a record value?
Sorry that's a bit of a crappy explanation - Let me try it this way.
I have a table which has the following fileds
myTable:
id (Primary Key, auto increment)
Description (VarChar)
Date (TimeStamp)
someData (VarChar)
orderval (smallint, unsigned)
Data is displayed in my PHP Application in the order of orderval e.g.
SELECT * FROM myTable ORDER BY `orderval`
The orderval column is required as the data needs to be displayed in a very specific order - not just in date order or sorted by description or whatever.
Usually the values increment in blocks of 10 at a time, i.e. 10, 20, 30, 40 ,50 so that if I need to insert a field between 10 and 20 I can set its orderval to 15 (Does this remind anyone of line-numbering in BASIC?)
It sometimes becomes necessary however for me to "renumber" the order val field.. e.g. the ordervals may go 10,11,12,13,14,15 and I need to insert one between 14 & 15. So I have to renumber the records so that 11 becomes 20, 12 becomes 30, 13 becomes 40 etc. etc.
I was considering writing a bit of PHP to do this, but I was wondering if there is any way of doing this directly under mysql? something like:
UPDATE myTable SET `orderval` = lastorderval+10
Any Ideas?
Many Thanks