switchdoc Posted September 4, 2006 Share Posted September 4, 2006 Hello, I am hoping you can give me a hand with this. It's basic but I can't get it to work.I have a mysql table with a bunch of steps in it:instruction1 "do this"instruction2 "do that"instruction3 "do the other thing".What I am trying to do is allow a user to add a step in the middle and then re-write the id numbers so they are still in order. i.e. the user would add instruction2 "do something different" and i would end up with:instruction1 "do this"instruction2 "do something different"instruction3 "do that"instruction4 "do the other thing".I've tried doing this in a while loop: (frameid is the number I am trying to increment)(I am limiting at the frame number the user wants to add at, and 2000 because I know there will never be that many steps)[code]$update = "select * from tutorialfiles2 where tutorial='$tutorial' limit $frameidupdate, 2000";$result = mysql_query($update) OR DIE ("There was an error" .mysql-error());while ($line = mysql_fetch_array($result)){$frameid = $line["frameid"];$stepname = $line["stepname"];$frameid2 = $frameid++;echo "<br><br>$frameid - $stepname <br>";$change = "update tutorialfiles2 set frameid='$frameid2' where frameid='$frameid'";$done = mysql_query($change) OR DIE ("There was an error" .mysql_error());[/code]but what I get is, for example:instruction1 "do this"instruction2 "do something different"instruction4 "do that"instruction4 "do the other thing".its not incrementing, its just adding the highest possible step.Any thoughts appreciated. I'll be around if you need more info as I realize this is clear as mud.Thanks,Switchdoc Quote Link to comment https://forums.phpfreaks.com/topic/19716-adding-to-mysql-table-and-incrementing-by-1-solved/ Share on other sites More sharing options...
switchdoc Posted September 5, 2006 Author Share Posted September 5, 2006 Well, I know why the while loop doesnt work.I am incrementing what I already incremented. I am SOOO dumb. i.e. I say set step5 to 6, set step 6 to 7, etc and since it runs one at a time the I just set 5 to 6 so not I am setting that same step to 7 so eventually they all equal the highest possible number. So, can't do this in a while loop..Any thoughts?-Switch Quote Link to comment https://forums.phpfreaks.com/topic/19716-adding-to-mysql-table-and-incrementing-by-1-solved/#findComment-86123 Share on other sites More sharing options...
switchdoc Posted September 5, 2006 Author Share Posted September 5, 2006 I got it. Trick is to do it in reverse. Get the total number of files, start at the end and do the writes backwards. That way you aren't incrementing what you just changed. Thanks anyway,-Switch Quote Link to comment https://forums.phpfreaks.com/topic/19716-adding-to-mysql-table-and-incrementing-by-1-solved/#findComment-86155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.