Jump to content

[SOLVED] Need help with updating all rows in mysql


pneudralics

Recommended Posts

I'm building a database with users. The table user has these 2 fields: contestpoints and totalpoints.

The below is to add the contestpoints to the totalpoints and save it.

 

My issue is it only takes one data from the various users and update everyone with the same data.

 

Users will have a variety of contestpoints and totalpoints.

 

I want to be able to hit submit and update all rows according to each different user not making everyone have the same totalpoints.

 

I've tried adding the id to my while loop and using the following in my query WHERE id = '$id'

<?php
if (isset($_POST['convertpointssubmit'])) {
$configconvertpoints = $_POST['convertpoints'];
if (!empty($configconvertpoints)) {
	if ($configconvertpoints == 'YES') {

		$convertpointsupdateq = "SELECT * FROM user";
		if ($convertpointsupdater = mysql_query($convertpointsupdateq)) {
			while ($convertpointsupdaterow = mysql_fetch_array ($convertpointsupdater)) {
			$convertcontestpoints = $convertpointsupdaterow['contestpoints'];	
			$converttotalpoints = $convertpointsupdaterow['totalpoints'];	
			$contestplustotal = "$convertcontestpoints" + "$converttotalpoints";
			}
		}

		$updateconvertpointsq = "UPDATE user SET totalpoints = '$contestplustotal'";
		if (mysql_query ($updateconvertpointsq)) {
		echo "<font color=\"red\">Contest points have been transfered to Total points!</font><br />";
			$resetcontestpointsq = "UPDATE user SET contestpoints = '0'";
			if (mysql_query ($resetcontestpointsq)) {
			echo "<font color=\"red\">Contest points have been reset to zero!</font>";
			}
			else {
			echo "<font color=\"red\">Contest points did not reset.</font>";
			}
		}
		else {
		echo "<font color=\"red\">Points did not transfer.</font>";
		}
	}
	else {
	echo "<font color=\"red\">You have chosen to not transfer points.</font>";
	}
}
else {
echo "<font color=\"red\">Transfer points submit is blank!</font>";
}	
}			
?>

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.