Jump to content

echo IF


fife

Recommended Posts

I want to echo this div below but only if there is more than one of these fields missing.  How would I go about this?

 

 

<?php 
		//only echo all of this if one or more of these fields does not exists so.......


if () {
		   echo"
	 <div id=\"items_todo\">
           <h3>Members Info</h3><br/>
         <ul>";
		if (empty($User['address_L1'])) { echo "<li><a href=\"#\">Update Address</a></li>";} 
		 elseif (empty($User['intro'])) {echo "<li><a href=\"#\">About You</a></li>";}
		elseif (empty($User['profile_image'])){echo "<li><a href=\"#\">Add Profile Image</a></li>";}
		elseif (empty($User['Nickname'])){echo "<li><a href=\"#\">Add A Nickname</a></li>";}
echo"</ul>
	 </div>";
    } ?>

Link to comment
Share on other sites

I think you could just do:


if (empty($User['address_L1']) || empty($User['intro']) || empty($User['profile_image']) || empty($User['Nickname'])) {


   echo"
<div id=\"items_todo\">
           <h3>Members Info</h3><br/>
         <ul>";

if (empty($User['address_L1'])) { echo "<li><a href=\"#\">Update Address</a></li>";} 

elseif (empty($User['intro'])) {echo "<li><a href=\"#\">About You</a></li>";}

elseif (empty($User['profile_image'])){echo "<li><a href=\"#\">Add Profile Image</a></li>";}
elseif (empty($User['Nickname'])){echo "<li><a href=\"#\">Add A Nickname</a></li>";}
echo"</ul>
</div>";

 

That way it will echo the div if one of those is empty and then move on the code you already have.

 

-Frank

Link to comment
Share on other sites

Here's a simpler way (and cleaner way) of doing this:

<?php
$tst = array('address_L1'=>'Update Address','intro'=>'About You','profile_image'=>'Add Profile Image','Nickname'=>'Add A Nickname');
$tmp = array();
foreach ($tst as $item => $txt) {
     if (empty($User[$item])) {
         $tmp[] = "<li><a href='#'>$txt</a></li>";
     }
}
if (!empty($tmp)) { // if $tmp is not empty a least one of the items tested was empty
   echo"
<div id='items_todo'>
           <h3>Members Info</h3><br/>
         <ul>";
   echo implode("\n",$tmp) . "\n";
   echo"</ul>
</div>";
?>

 

Ken

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.