SirChick Posted October 14, 2007 Share Posted October 14, 2007 Problem.... I have this script which is to run regardless of who's logged in as its meant to update fields. The problem i am facing is... users can be a paying member, and so i want to update their field different to the non paying members. So i need to find a way to check each and every record so that if the field DonatorDaysLeft is greater than 0 then do the first sql in the code below.. else do the other sql But i don't know how to incorporate such an idea... <? $connect = mysql_connect("localhost", "root", "nottelling"); //error handle if (!$connect) { echo "Unable to connect to DataBase: " . mysql_error(); exit; } //error handle if (!mysql_select_db("civilian")) { echo "Unable to select table: " . mysql_error(); exit; } //something needs to be here If ($DonateDays > 0){ $sql = "UPDATE userregistration SET CurrentEnergy=CurrentEnergy+10 WHERE CurrentEnergy<MaxEnergy"; $sqlresult = mysql_query($sql) or die(mysql_error()); Echo 'Success'; } Else { $sql2 = "UPDATE userregistration SET CurrentEnergy=CurrentEnergy+5 WHERE CurrentEnergy<MaxEnergy"; $sqlresult = mysql_query($sql2) or die(mysql_error()); Echo 'Success2'; } ?> Link to comment https://forums.phpfreaks.com/topic/73237-solved-update-all-users-with-certain-criteria/ Share on other sites More sharing options...
Barand Posted October 14, 2007 Share Posted October 14, 2007 try <?php $sql = "UPDATE userregistration SET CurrentEnergy = CurrentEnergy + IF(DonatorDaysLeft > 0, 10, 5) WHERE CurrentEnergy < MaxEnergy"; ?> Link to comment https://forums.phpfreaks.com/topic/73237-solved-update-all-users-with-certain-criteria/#findComment-369553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.