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()); } ?> Link to comment https://forums.phpfreaks.com/topic/36595-solved-mysql-and-deincrement/ 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' Link to comment https://forums.phpfreaks.com/topic/36595-solved-mysql-and-deincrement/#findComment-174293 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. Link to comment https://forums.phpfreaks.com/topic/36595-solved-mysql-and-deincrement/#findComment-174301 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? Link to comment https://forums.phpfreaks.com/topic/36595-solved-mysql-and-deincrement/#findComment-174308 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 Link to comment https://forums.phpfreaks.com/topic/36595-solved-mysql-and-deincrement/#findComment-174312 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.