Jump to content

MYSQL php update adding extra number


lucas20

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.