ferrin Posted May 8, 2010 Share Posted May 8, 2010 this is probably really basic, but how do i go about adding '1' to each item in a row? for example, i have a cron set to run a page every hour, and every hour it updates a number under the column 'time' for each column with breeding = 'yes'. then after the number reaches 20, breeding is reset to = 'no'. this is my code (what i figured out so far), but it's not doing anything. don't kill me, i'm still a newb. <?php if ($number < 20) { $con = mysql_connect ("gamepets.db.6086537.hostedresource.com","gamepets","----") or die(mysql_error()); mysql_select_db("gamepets")or die("cannot select DB"); // // ------------ GET NUMBER FROM DATABASE -------- $sql=("SELECT time FROM test WHERE breeding = 'yes'"); $number=mysql_query($sql); $number++; // ------------- ADD +1 ($add) to time ---------------- // Connect to server and select database. $con = mysql_connect ("gamepets.db.6086537.hostedresource.com","gamepets","----") or die(mysql_error()); mysql_select_db("gamepets")or die("cannot select DB"); $number = mysql_query("UPDATE test SET time='$number' WHERE breeding='yes'") or die(mysql_error()); } else { $con = mysql_connect ("gamepets.db.6086537.hostedresource.com","gamepets","----") or die(mysql_error()); mysql_select_db("gamepets")or die("cannot select DB"); $number = mysql_query("UPDATE test SET breeding='no' WHERE time='100'") or die(mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted May 8, 2010 Share Posted May 8, 2010 Your code is seriously flawed. Firstly, you have an if statement that checks to see if a non-existent variable ($number) is less than 20. $number does not exist yet. Even when it does exist, no where in your code is it ever set to a number. Quote Link to comment Share on other sites More sharing options...
ignace Posted May 8, 2010 Share Posted May 8, 2010 Like thorpe said your code is seriously flawed: if ($number < 20) This is what -sort of- happens when it executes 1. $number? 2. $number = null 3. $number = (int) null 4. $number = 0 5. $number < 20 6. true $number=mysql_query($sql); $number++; 1. $number = Resource #[iD] 2. $number++ 3. $number = 0 $number = mysql_query("UPDATE test SET time='$number' WHERE breeding='yes'") $number = Resource #[iD] 1) As you can see $number never goes higher then 0 2) If you are hoping $number will keep increasing with every request, you are dead wrong. 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.