Re: Inserting data without a reference in the row.
| From: | heilo | Date: | Sun, 20 Apr 2003 23:24:53 +0000 |
| Subject: | Re: Inserting data without a reference in the row. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27202@lists.php.net to get a copy of this message | ||
Hi!
Here is my suggestion:
First of all you have to number all your entries ascending. Everytime you
delte a entry you have to know the primary key and the number so that you
can adapt the other numbers. Lets imagine you want to delete the entry with
the primary key (which is also an integer, may be also an auto increment?)
325. So you call the script maybe in this manner:
index.php?reason=delete&primkey=325
$primkey = $_GET['primkey']; // which is 325
// get the number
$qry = 'SELECT
number FROM table WHERE
primkey='.$primkey;
$number = mysql_fetch_array(mysql_query($qry));
$number = $number['number'];
// delete the entry
$qry = 'DELETE FROM table WHERE primkey='.$primkey;
$res = mysql_query($qry);
// update the other entries, so there is no whole
$qry = 'UPDATE table SET number=number-1 WHERE
number>'.$number;
Thats it.
Hope this helps,
.ma
Raymond Lilleødegård <rhov@c2i.net> wrote@21.04.2003 1:11 Uhr:
> Hi!
>
> I'm trying to add a new column in my moviedatabase because I want to have a
> movienumber that doesn't have "holes" between the movies when I delete a
> movie. So I have to update the new column with increasing numbers. Is it
> possible to refer to row with a mysqlnumer of any kind?
>
> Best regards Richard
>
>
Matthias Steinböck
Email: grillen@abendstille.at
Web: http://www.abendstille.at
Frühabendliches Webdesign.
------------------------------------------
Im Übrigen sind wir der Meinung, dass
Computerspielen das 3D-Denken fördert.
Gratis Computerspiele für alle!!!