Re: Re: php mysql problem
| From: | Richard Lynch | Date: | Wed, 03 May 2006 09:31:45 +0000 |
| Subject: | Re: Re: php mysql problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235334@lists.php.net to get a copy of this message | ||
On Tue, May 2, 2006 7:05 am, Ross wrote:
> This is my database now...I will use the item_id for the order but
> what if I
> want to change item_id 3 to item id 1? How can I push all the items
> down one
> place? How can I delete any gaps when items are deleted.
Change item_id 3 to 1.
... select id from board_papers where item_id = 3
... $id3 = mysql_result($result);
... select id from board_papers where item_id = 1
... $id1 = mysql_result($result);
... update board_papers set item_id = 1 where id = $id3
... update board_papers set item_id = 3 where id = $id1
Delete an item:
$item_id = 42;
... delete from board_papers where item_id = 42
... update board_papers set item_id = item_id - 1 where item_id > 42
It's up to you to actually add all the function calls and quotes and
error-checking and make it work for variables instead of constants.
--
Like Music?
http://l-i-e.com/artists.htm