Re: Taking X records, removing one record in the middle, then renumber...
| From: | Pavel Jartsev | Date: | Mon, 06 Nov 2000 15:09:14 +0000 |
| Subject: | Re: Taking X records, removing one record in the middle, then renumber... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-23892@lists.php.net to get a copy of this message | ||
Mark Lipscombe wrote:
>
> <skipped ...>
>
> With PHP, I'm trying to work out some sort of algorithm that would, in a
> reasonably optimised fashion, enable me to do the following:
>
> Delete record 3 - obviously mysql_query("DELETE FROM table_name WHERE cid =
> 3")
> Then move anything after three up one spot, hence leaving the table with 1,
> 2, 3 & 4, so no holes in the numbering.
>
Hi!
I don't know is it reasonably optimised or not, but one solution might
be:
<?
function delete_o_matic( $victim_id )
{
/* update other lucky items ... */
mysql_query( "UPDATE table_name SET cid=cid-1 WHERE cid > ".$victim_id
);
/* ... and delete victim */
mysql_query( "DELETE FROM table_name WHERE cid=".$victim_id );
}
?>
Maybe this is what You need. :)
--
Pavel a.k.a. Papi