Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> desc Gallery;
- +--------------+------------------+------+-----+-------------------+-----------------------------+
- | Field | Type | Null | Key | Default | Extra |
- +--------------+------------------+------+-----+-------------------+-----------------------------+
- | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
- | title | varchar(255) | NO | | NULL | |
- | subtitle | varchar(255) | NO | | NULL | |
- | description | varchar(5000) | NO | | NULL | |
- | date | datetime | NO | | NULL | |
- | isActive | tinyint(1) | NO | | NULL | |
- | lastModified | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
- +--------------+------------------+------+-----+-------------------+-----------------------------+
- mysql> desc Image;
- +--------------+------------------+------+-----+-------------------+-----------------------------+
- | Field | Type | Null | Key | Default | Extra |
- +--------------+------------------+------+-----+-------------------+-----------------------------+
- | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
- | galleryId | int(10) unsigned | NO | MUL | NULL | |
- | description | varchar(250) | YES | | NULL | |
- | path | varchar(250) | NO | | NULL | |
- | lastModified | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
- +--------------+------------------+------+-----+-------------------+-----------------------------+
- UPDATE table set order=order+1 where order>='orderValueOfItemYouCareAbout';
- mysql> SELECT id, galleryId, description, displayOrder FROM Image ORDER BY displayOrder;
- +-----+-----------+----------------------------------+--------------+
- | id | galleryId | description | displayOrder |
- +-----+-----------+----------------------------------+--------------+
- | 271 | 20 | NULL | 1 |
- | 270 | 20 | Tracks leading into the ocean... | 2 |
- | 278 | 20 | NULL | 3 |
- +-----+-----------+----------------------------------+--------------+
- 3 rows in set (0.00 sec)
- UPDATE Image SET displayOrder =
- CASE displayOrder
- WHEN 2 THEN 3
- WHEN 3 THEN 2
- END
- WHERE galleryId = 20
- AND displayOrder BETWEEN 2 AND 3;
- mysql> SELECT id, galleryId, description, displayOrder FROM Image ORDER BY displayOrder;
- +-----+-----------+----------------------------------+--------------+
- | id | galleryId | description | displayOrder |
- +-----+-----------+----------------------------------+--------------+
- | 271 | 20 | NULL | 1 |
- | 278 | 20 | NULL | 2 |
- | 270 | 20 | Tracks leading into the ocean... | 3 |
- +-----+-----------+----------------------------------+--------------+
- 3 rows in set (0.00 sec)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement