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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.