grantp22 Posted September 16, 2009 Share Posted September 16, 2009 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! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/174404-i-include-php-subs-in-a-html-tag-using-echo/ Share on other sites More sharing options...
Adam Posted September 16, 2009 Share Posted September 16, 2009 Excuse my possible ignorance, but why don't you just use the first version?? I can't say I understand why you're try to echo out the actual PHP code... Quote Link to comment https://forums.phpfreaks.com/topic/174404-i-include-php-subs-in-a-html-tag-using-echo/#findComment-919394 Share on other sites More sharing options...
Cetanu Posted September 16, 2009 Share Posted September 16, 2009 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?!?!! Quote Link to comment https://forums.phpfreaks.com/topic/174404-i-include-php-subs-in-a-html-tag-using-echo/#findComment-919744 Share on other sites More sharing options...
The PHP Guy Posted September 18, 2009 Share Posted September 18, 2009 <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. Quote Link to comment https://forums.phpfreaks.com/topic/174404-i-include-php-subs-in-a-html-tag-using-echo/#findComment-920480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.