pneudralics Posted May 17, 2009 Share Posted May 17, 2009 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>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/158467-solved-need-help-with-updating-all-rows-in-mysql/ Share on other sites More sharing options...
trq Posted May 17, 2009 Share Posted May 17, 2009 You could get this done with a few simple queries, not loops or SELECT queries. UPDATE users SET totalpoints = (contestpoints+totalpoints); Then, UPDATE user SET contestpoints = 0; Link to comment https://forums.phpfreaks.com/topic/158467-solved-need-help-with-updating-all-rows-in-mysql/#findComment-835724 Share on other sites More sharing options...
pneudralics Posted May 17, 2009 Author Share Posted May 17, 2009 Thanks. Just what I needed. Link to comment https://forums.phpfreaks.com/topic/158467-solved-need-help-with-updating-all-rows-in-mysql/#findComment-835727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.