Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 0.42 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Handling numerical lists in php and MySQL
  2. Id | position | person
  3. ======================
  4. 1  | 3        | John
  5. 2  | 1        | Jane
  6. 3  | 4        | David
  7. 4  | 2        | Emily
  8.        
  9. ...order by position, person
  10.        
  11. for i in new pos+1..old pos
  12.     pos[i]++
  13.        
  14. SET @position = 0;
  15. UPDATE calendar_events SET position = @position := @position + 1
  16. WHERE position >= 0
  17. ORDER BY position, IF(calendar_event_id = 7, 0, 1), name