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{ ?> Code (text): 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> Code (text): 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! Thanks
Oh My God! You can't put php code in a echo! I think you have to build a better piece of php code to do what you want to, but without put php code in echo!
If the first PHP example is what you need why don't you use it, i.e. try it and see if it works? In the second example, you are echo PHP statements as text, i.e. you are telling PHP to output statements looking like PHP to the web browser.
if you want the first script to output inside a TD tag, include that file inside the tag or use eval function. The second script wont be helping your case and it is not a valid approach.