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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.