Jump to content

Recommended Posts

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>";

Link to comment
https://forums.phpfreaks.com/topic/137216-mysql-php-update-adding-extra-number/
Share on other sites

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'] . "";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.