SlickAU Posted August 13, 2007 Share Posted August 13, 2007 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 Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 13, 2007 Share Posted August 13, 2007 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"]) } Quote Link to comment Share on other sites More sharing options...
SlickAU Posted August 15, 2007 Author Share Posted August 15, 2007 Cheers Lemmin, I will test this out today... I will get back to you once i have attempted it.. Slick Quote Link to comment Share on other sites More sharing options...
SlickAU Posted August 20, 2007 Author Share Posted August 20, 2007 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? Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 22, 2007 Share Posted August 22, 2007 Looks right to me. I would suggest echoing out the variables that are in use to see if they match. I would echo them all out in the while loop. Quote Link to comment Share on other sites More sharing options...
Hypnos Posted August 22, 2007 Share Posted August 22, 2007 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()? Quote Link to comment Share on other sites More sharing options...
SlickAU Posted August 24, 2007 Author Share Posted August 24, 2007 Did you remeber mysql_connect() and mysql_select_db()? Yep, I sure did... Still havent found a solution to this problem Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 My guess is that your query isn't returning any results. Before the while loop and after the $qry, put this line: echo mysql_num_rows($qry); See if it returns anything greater than zero. Quote Link to comment 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.