Jump to content

I include PHP subs in a html <TD> tag using echo


grantp22

Recommended Posts

How can I include PHP IF-ELSE subs in a html <TD> tag using echo, for example, I need to do the following:

 

<?
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "
       ."[<a href=\"useredit.php\">Edit Account</a>]   ";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>]   ";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
}
else{
?>

 

And this is what I have, see below, but it doesn't work correctly, the IF-Else get ignored:

 

<TD height="82" align="center" style="font-size: 8pt"><? echo "<b>Member Total:</b> ".$database->getNumMembers(); ?>
<p><? echo "There are ".$database->num_active_users; ?><? echo " registered members and ".$database->num_active_guests; ?><? echo " guests viewing the site."; ?></p>
<p>
   <? echo "<?"; ?> 
   <? echo "if(".$session->logged_in; ?><? echo "){"; ?>
   <? echo "<h1>Logged In</h1>"; ?>
   <? echo "Welcome <b>".$session->username; ?><? echo "</b>, you are logged in. <br><br>"; ?>
   <? echo "[<a href=\"userinfo.php?user=".$session->username; ?><? echo "\">My Account</a>]   "; ?>
   <? echo "[<a href=\"useredit.php\">Edit Account</a>]   "; ?>
   <? echo "if(".$session->isAdmin(); ?><? echo "){"; ?>
   <? echo "[<a href=\"admin/admin.php\">Admin Center</a>]   "; ?>
   <? echo "}"; ?>
   <? echo "[<a href=\"process.php\">Logout</a>]"; ?>
   <? echo "}"; ?>
   <? echo "else{"; ?>
   <? echo "?>"; ?>
</p>
</TD>

 

I basically just need to have this subroutine in my table data cell, any help will be much appreciated, coz this is driving me nuts!  :confused:

 

Thanks

Link to comment
Share on other sites

<TD height="82" align="center" style="font-size: 8pt"><? echo "<b>Member Total:</b> ".$database->getNumMembers(); ?>
<p><? echo "There are ".$database->num_active_users; ?><? echo " registered members and ".$database->num_active_guests; ?><? echo " guests viewing the site."; ?></p>
<p>
   <? echo "<?"; ?> 
   <? echo "if(".$session->logged_in; ?><? echo "){"; ?>
   <? echo "<h1>Logged In</h1>"; ?>
   <? echo "Welcome <b>".$session->username; ?><? echo "</b>, you are logged in. <br><br>"; ?>
   <? echo "[<a href=\"userinfo.php?user=".$session->username; ?><? echo "\">My Account</a>]   "; ?>
   <? echo "[<a href=\"useredit.php\">Edit Account</a>]   "; ?>
   <? echo "if(".$session->isAdmin(); ?><? echo "){"; ?>
   <? echo "[<a href=\"admin/admin.php\">Admin Center</a>]   "; ?>
   <? echo "}"; ?>
   <? echo "[<a href=\"process.php\">Logout</a>]"; ?>
   <? echo "}"; ?>
   <? echo "else{"; ?>
   <? echo "?>"; ?>
</p>
</TD>

 

Won't work coz you can't make PHP evaluate code by echoing it.

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.