Jump to content

[SOLVED] updating rows in table


sarathi

Recommended Posts

I am working on making a blog, and I have each blog set to have an id, but when a post is deleted, I want all the post with a greater id to lower by one, so there is no gap in the ids. I am trying to use a for loop like this:

$post is the id of the post being deleted.

$rows is the number of rows in the table

$change is the ids in the table

for($i=0;$i<$rows;$i++)
{
$update=mysql_result($change, $i)-1;
mysql_query("UPDATE blogs SET id='$update' WHERE id>$post");
}

but when i use this, all the ids greater than the post being deleted end up being 0.

 

If anyone has any ideas, they would help me alot.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/167753-solved-updating-rows-in-table/
Share on other sites

Well, I set the new posts Id by how many rows are in the database, and so the id's of later post will be mixed up later on.

 

I have looked into auto increment, but when I look at the type of fields in the database for a new column, I can't find the auto increment type.

 

Nvm, I just found out how to add auto increment.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.