slaterino Posted July 30, 2009 Share Posted July 30, 2009 Hi, I am creating and IF/ELSE statement. I want the IF statement to ask for one specific condition to be met, and if that condition is not met, there will be an ELSE statement run instead. My only problem is how do I get this query to run the ELSE statement once. At the moment, using my query below it will run the ELSE statement for each field in the database with contact_id=$mye_id as specified in my query here but where $contribution_type_id does not equal '8', as in the part of my query lower down. How can I change this so the ELSE statement only runs the once? Thanks Russ $query = "SELECT contact_id, contribution_type_id FROM civicrm_contribution WHERE contact_id=$mye_id"; $result = mysql_query($query) or die('Error, list committee members failed. ' . mysql_error()); while(list($contact_id, $contribution_type_id) = mysql_fetch_array($result)) { if ($contact_id === $mye_id AND $contribution_type_id === '8') { echo 'First statement'; } else { echo 'Second statement'; } } Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 Not sure if I understood what you mean but did you mean you want to end the while loop when it goes inside the else condition? If so just add break inside the else. <?php while (something) { if (condition) { } else { break; } } Quote Link to comment Share on other sites More sharing options...
slaterino Posted July 30, 2009 Author Share Posted July 30, 2009 You're a genius! Works perfectly! 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.