spfoonnewb Posted February 1, 2007 Share Posted February 1, 2007 Can anyone help me get this code working, I need it to select each row that isn't equal to zero, and subtract one from it... <?php //Db info $result = mysql_query("SELECT cst FROM my_db WHERE cst != '0'") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { $stamp[] = $row['cst']; $stamp[]--; mysql_query("UPDATE my_db SET cst = '$stamp[]'") or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 UPDATE my_db set cst=cst-1 WHERE cst != '0' Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted February 1, 2007 Author Share Posted February 1, 2007 They are equal to 24, using that makes them equal to -1282 I should mention that there are thousands of rows, and I only want them each updated once. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 1, 2007 Share Posted February 1, 2007 What? That doesn't make any sense. You ran the query I wrote and they all changed to -1282? What datatype is the field? Quote Link to comment Share on other sites More sharing options...
spfoonnewb Posted February 1, 2007 Author Share Posted February 1, 2007 Oh, wait I forgot the X out the while statement lol 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.