Re: Inserting data without a reference in the row.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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!!!


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux