HDFilmMaker2112 Posted June 20, 2011 Share Posted June 20, 2011 Can the following be condensed into one query? $username=sanitize($_POST['username']); $sql="SELECT * FROM $tbl_name WHERE username='$username' AND email='$email' AND amount='$donation_amount'"; $result=mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows==1){ $sql1="UPDATE $tbl_name SET password='$new_password' WHERE username='$username' AND email='$email' AND amount='$donation_amount'"; $result1=mysql_query($sql1); $num_rows1=mysql_affected_rows(); Should I just throw out the SELECT and just use the update? $num_rows1 will equal 0 if it doesn't find an entry to update correct? Link to comment https://forums.phpfreaks.com/topic/239845-condense-mysql-query/ Share on other sites More sharing options...
ebmigue Posted June 20, 2011 Share Posted June 20, 2011 Yep, you could omit the SELECT and $num_rows part. The UPDATE clause suffices: record(s) found according to your predicate (i.e., WHERE condition) will be updated as specified in the SET clause; if no records are found, the table/relvar will be "as is" (i.e., no update will take place.) Hope it helps. Link to comment https://forums.phpfreaks.com/topic/239845-condense-mysql-query/#findComment-1232007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.