lucas20 Posted December 16, 2008 Share Posted December 16, 2008 Wondering if anyone knew why the following code was adding +2 instead of +1. It is out of all while/loop statements. Each of the echo statements appear once and are correct (add only one to the next week). However, looking at the database it jumps say from week 2 to week 4 instead of week 2 to week 3 $currentweek = mysql_result(mysql_query("SELECT week from WEEK WHERE week>0"),0); echo $currentweek; $newweek=$currentweek+1; echo "<br>New week: $newweek<br>"; $query7 = "update WEEK SET week=$newweek WHERE week>0"; mysql_query($query7) or die('Week update failed:' . mysql_error()); ; $value = mysql_result(mysql_query("SELECT week from WEEK WHERE week>0"),0); echo "<center><h2>Week updated as well $value</h2>"; Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/ Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 You need to use: strtotime('+1 week'); Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-716825 Share on other sites More sharing options...
lucas20 Posted December 16, 2008 Author Share Posted December 16, 2008 That's not it, it is just an integer, not a part of the php time functions Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-716841 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 If it's an integer, why don't you just add 1 inside the query? $query7 = "update WEEK SET week=week+1 WHERE week>0"; Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-716849 Share on other sites More sharing options...
lucas20 Posted December 16, 2008 Author Share Posted December 16, 2008 ya i tried that too, same thing bumps it by 2 - i added the variable so that i could troubleshoot Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-716874 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 Try this: $query7 = "update WEEK SET week=week+1 WHERE week > 0"; mysql_query($query7) or die('Week update failed:' . mysql_error()); ; $value = "SELECT week FROM WEEK WHERE week > 0"; $result = mysql_query($value) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo "Week updated as well " . $row['week'] . ""; } Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-716883 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 MISTAKE (extra semi-colon, but I'm sure you would have figured that out ), change this line to: mysql_query($query7) or die('Week update failed:' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-716894 Share on other sites More sharing options...
PFMaBiSmAd Posted December 17, 2008 Share Posted December 17, 2008 Your browser is probably requesting the page twice. What browser are you using? Exactly how is the page being requested, a link, a form submission? Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-717212 Share on other sites More sharing options...
fenway Posted December 17, 2008 Share Posted December 17, 2008 Your browser is probably requesting the page twice. What browser are you using? Exactly how is the page being requested, a link, a form submission? Sigh... don't people use redirects? Quote Link to comment https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/#findComment-717409 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.