Jump to content

[SOLVED] Help to add ELSE ECHO statement


bgbs

Recommended Posts

To the php statement below I would like to add one more option that if it does not meet any of the required member statuses that it would simply read FREE MEMBER. Is it possible to add that statement if we dont have mem_type_id set for free member in the database?

   

 

 

 

 

 <?PHP 
		if($admin=="yes")
		{
			$cur_mem = $db->get_row("SELECT * FROM mem WHERE user_id = '$v_id'");

			if($cur_mem->mem_type_id == 2)
				echo "<strong><span style=\"color: red; \">LIFETIME MEMBER</span></strong>";
			elseif($cur_mem->mem_type_id == 3)
				echo "       <strong><span style=\"color: red; \">6 MONTH MEMBER</span></strong>";
			elseif($cur_mem->mem_type_id == 4)
				echo "<strong><span style=\"color: red; \">ANNUAL MEMBER</span></strong>";
			elseif($cur_mem->mem_type_id == 6)
				echo "<strong><span style=\"color: red; \">MONTHLY MEMBER</span></strong>";
			elseif($cur_mem->mem_type_id == 7)
			 echo "<strong><span style=\"color: red; \">QUARTERLY MEMBER</span></strong>";
			elseif($cur_mem->mem_type_id == 10) {
				echo "<strong><span style=\"color: red; \">EXPIRED MEMBER</span></strong>";
					if($cur_mem->renew_refused == "Yes")
						echo "<br /><span style=\"color:red\">Renewal refused</span> ".$cur_mem->refused_date;
			}	
		}?>

Link to comment
https://forums.phpfreaks.com/topic/180288-solved-help-to-add-else-echo-statement/
Share on other sites

Could make this much cleaner using a switch:

 

            switch ($cur_mem->mem_type_id)
            {
                case 2:
                    echo "<strong><span style=\"color: red; \">LIFETIME MEMBER</span></strong>";
                    break;
                case 3:
                    echo "       <strong><span style=\"color: red; \">6 MONTH MEMBER</span></strong>";
                    break;
                case 4:
                    echo "<strong><span style=\"color: red; \">ANNUAL MEMBER</span></strong>";
                    break;
                case 6:
                    echo "<strong><span style=\"color: red; \">MONTHLY MEMBER</span></strong>";
                    break;
                case 7:
                    echo "<strong><span style=\"color: red; \">QUARTERLY MEMBER</span></strong>";
                    break;
                case 10:
                    echo "<strong><span style=\"color: red; \">EXPIRED MEMBER</span></strong>";
                    if($cur_mem->renew_refused == "Yes")
                        echo "<br /><span style=\"color:red\">Renewal refused</span> ".$cur_mem->refused_date;
                    break;
                default:
                    echo "<strong><span style=\"color: red; \">FREE MEMBER</span></strong>";
            }

 

You could even tidy it up further placing the "<strong><span...." stuff before and after the switch removing the repetition.

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.