Hi all. In the project I'm working on, I've got a table with ids that are
written based on how many records are in the table. i.e., the first
record
has an ID of 1, the 50th is 50, etc. When a row gets deleted (I created a
web interface, I don't want all these members using phpMyAdmin), the ID's
of
all the records after it are supposed to be decremented by one. I thought
it was working, but yesterday it didn't. Can anyone see what I'm doing
wrong?
Like, doing what you are doing is just a Bad Idea in general...
I know it offends your organizational sensibilities to have holes in your ID
scheme, but it's really better in the long run...
You see, at some point, you may have another table with things in it that
need to be cross-referenced to the things in this table. When that happens,
you really don't want to run around trying to update all those tables at
once -- Because while you're still halfway through that process, somebody
will be surfing to look at record #42 -- And whatevery is associated with
#42 in the other table, well, you haven't updated that yet, because they are
surfing at the same exact instant that your updates are taking place... So
they are going to get the old 42's cross-references and be all confused.
Still, just in case you really, really need this 1-50 thing, you can do
it -- Just keep the *real* ID internally and when you delete, don't mess
with that.
Probably the easiest way to renumber them is like this:
$query = "update $tablename set fields[0] = fields[0] - 1 where fields[0]
$editval";
***
if ($delete == 1){
#delete the row
$worked = mysql_query("delete from $tablename where
$fields[0]=\"$editval\" ", $database);
if (!$worked){
echo "couldn't delete anythingp";
}//end if
$connection =
@mysql_connect("localhost",$PHP_AUTH_USER,$PHP_AUTH_PW);
$database = @mysql_select_db($databasename, $connection);
$del = mysql_query("select * from $tablename where RestID =
$restidval", $database);
while ($Info_Array = mysql_fetch_array($del)){
#update the ids of each record
if($Info_Array[$v] $editval){ #v is a fieldname (specifically
the id) defined above
mysql_query("update $tablename set $fields[0] =
($fields[0]-1) where $fields[0] = \"$Info_Array[$v]\" ", $database);
}//end if
}//end while
$delete=0; #reset the delete flag
}//end if
***
Assume that all the variables have the values they're supposed to (cuz
last
I checked, they do. :))
Thanks for your help. Again.
Jason
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]