Jump to content

Increment cell values after THIS cell


SlickAU

Recommended Posts

Hey all,

 

I am trying to create a query which will increment ALL values in the 'frame' column of my table AFTER the current frame number, the current frame number is passed through via a form; here is an example:

 

BEFORE TABLE:

 

====================

id == frame ==

0 ==    0    == Already has content in this frame

1 ==    1    == Already has content in this frame

2 ==    2  == Already has content in this frame

3 ==    3  == Already has content in this frame

====================

 

Say i wanted to insert a new blank frame AFTER frame 1...the output should look like this:

 

$frameno = 1 ;

 

====================

id == frame ==

0 ==    0    == Content unchanged

1 ==    1    == Content unchanged

2 ==    2  == (no content in this frame...because this is a new field)

3 ==    3  == This contains the original content from frame 2

4 ==    4  == This contains the original content from frame 3

 

====================

 

So basically all i am trying to acheive is to increment all the frame fields after the chosen frame number and add a blank field after this chosen one.

 

Anyone have any ideas?

 

Thanks,

Slick ;D

 

 

Link to comment
Share on other sites

Assuming all the frame numbers are unique, this should work:

 

$qry = mysql_query("SELECT * FROM table WHERE frame > 1");
while ($row = mysql_fetch_array($qry))
{
mysql_query("UPDATE table SET frame = " . ($row["frame"]+1) . " WHERE frame = " . $row["frame"])
}

Link to comment
Share on other sites

Hey lemm,

 

I tried your suggestion, but to no avail...all that comes up now is a blank page when the script is run  >:(... Here is what i am using at the moment:

 

$frameno = $_GET['frameno'];

$refname = $_GET['refname']; /* Refname is the name of the course in which the frame is being edited.... e.g. - workplace inductiion */

 

//////// MYSQL CONNECTION INFO + SELECT DATABASE HERE ///////

 

$qry = mysql_query("SELECT * FROM $refname WHERE frame > $frameno");

while ($row = mysql_fetch_array($qry))

{

mysql_query("UPDATE $refname SET frame = " . ($row["frameno"]+1) . " WHERE frame = " . $row["frameno"])

echo "Success";

}

 

Any more suggestions?

Link to comment
Share on other sites

Hey lemm,

 

I tried your suggestion, but to no avail...all that comes up now is a blank page when the script is run  >:(... Here is what i am using at the moment:

 

$frameno = $_GET['frameno'];

$refname = $_GET['refname']; /* Refname is the name of the course in which the frame is being edited.... e.g. - workplace inductiion */

 

//////// MYSQL CONNECTION INFO + SELECT DATABASE HERE ///////

 

$qry = mysql_query("SELECT * FROM $refname WHERE frame > $frameno");

while ($row = mysql_fetch_array($qry))

{

mysql_query("UPDATE $refname SET frame = " . ($row["frameno"]+1) . " WHERE frame = " . $row["frameno"])

echo "Success";

}

 

Any more suggestions?

Did you remeber mysql_connect() and mysql_select_db()?
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.