sarathi Posted July 28, 2009 Share Posted July 28, 2009 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 More sharing options...
smerny Posted July 28, 2009 Share Posted July 28, 2009 why worry about gap in id? that could end up being a massive strain if you end up having any large amount of rows Link to comment https://forums.phpfreaks.com/topic/167753-solved-updating-rows-in-table/#findComment-884622 Share on other sites More sharing options...
sarathi Posted July 28, 2009 Author Share Posted July 28, 2009 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. Link to comment https://forums.phpfreaks.com/topic/167753-solved-updating-rows-in-table/#findComment-884630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.