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

I too have the same question...why not use the top one? The bottom one looks like a mess. Why don't you just have EVERYTHING in a <?php tag

 

??

Would that be easier than <? blahblah ?> over and over and over?!?!!

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

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.