Jump to content

Need help with ELSE statement


slaterino

Recommended Posts

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';
}
}

Link to comment
https://forums.phpfreaks.com/topic/168179-need-help-with-else-statement/
Share on other sites

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;
   }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.