cooldude832 Posted November 26, 2007 Share Posted November 26, 2007 Lets say I run a query, but its an update query that doesn't update anything (it sets a value to the same thing) integer field. Can I tell if it didn't do anything, without initally querying the previious information. My point to this is I have a reservation system I am designing and when an admin updates the status on your reservation (this is done in bulk) I want to email you that your status has changed, but I don't want to have to do 2 queries each time. Any ideas?? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 26, 2007 Share Posted November 26, 2007 First do a query to check if the value is the same, then if it isn't, do the update. Yes...this would take an extra query, but it's necessary and really isn't that much to handle. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 26, 2007 Share Posted November 26, 2007 or you can add a check box on the bottom that will ask you to update or not send email or not something like that help you minimize the work of your db... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 26, 2007 Author Share Posted November 26, 2007 well i found a better way, update queries return nothing of mysql_affected_rows so basically I run my updates in a loop with mysql_affected_rows() right after like this <?php $queries = array(); foreach($_POST['data'] as $key => $value){ $queries[$key] = "Update `".SALES_TABLE."` Set Status= '".$value."' Where SaleID = '".$key."'"; } $emails = array(); foreach($queries as $key => $value){ $tempr = mysql_query($value) or die(mysql_error()); if(mysql_affected_rows()>0){ $emails[] = $key; } } ?> then from that list of keys I run one more query that gets me the data to stuff in my emails that I will send. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.