Jump to content

adding to mysql table and incrementing by 1 (SOLVED)


switchdoc

Recommended Posts

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
Link to comment
Share on other sites

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