Andrew R Posted November 30, 2006 Share Posted November 30, 2006 Can anybody tell me why this script below isn't working. As you can see if page = names it will echo that. The problem is inside the echo I have some php. I tried putting the php in "" but it still comes up with an error.[code] <?if ($page == 'names'){ echo"</td> </tr> <tr class=\"navtext2\"> <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\"> <div align=\"left\"><font color=\"#747474\">" echo $row_names['fullname']; "</font></div> </div> <div> <div align=\"left\"></div> </div> <div></div></td> </tr>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28995-php-inside-html/ Share on other sites More sharing options...
pikemsu28 Posted November 30, 2006 Share Posted November 30, 2006 When you want to echo variables inside html, do not use echo use the period (.) before and after the variable.[code]<?if ($page == 'names'){ echo"</td> </tr> <tr class=\"navtext2\"> <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\"> <div align=\"left\"><font color=\"#747474\">" .$row_names['fullname']."</font></div> </div> <div> <div align=\"left\"></div> </div> <div></div></td> </tr>";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28995-php-inside-html/#findComment-132845 Share on other sites More sharing options...
The Little Guy Posted November 30, 2006 Share Posted November 30, 2006 [quote]When you want to echo variables inside html, do not use echo use the period (.) before and after the variable.[/quote]Its ok for him, he is using double quotes, which you can echo out vars without having to use the periodThe problem is probably this part though: echo $row_names['fullname'];its already in an echo, you don't need to add another one, so change it to this: [CODE] <?phpif ($page == 'names'){ echo"</td> </tr> <tr class=\"navtext2\"> <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\"> <div align=\"left\"><font color=\"#747474\"> {$row_names['fullname']} </font></div> </div> <div> <div align=\"left\"></div> </div> <div></div></td> </tr>";}?>[/CODE] Quote Link to comment https://forums.phpfreaks.com/topic/28995-php-inside-html/#findComment-132848 Share on other sites More sharing options...
wildteen88 Posted November 30, 2006 Share Posted November 30, 2006 A better option is use the HEREDOC syntax, no need to escape any quotes:[code=php:0]<?phpif ($page == 'names'){ echo <<<HTML_CODE</td> </tr> <tr class="navtext2"> <td height="22" colspan="3" valign="top"> <div id="navcontainer"> <div align="left"><font color="#747474"> {$row_names['fullname']} </font></div> </div> <div> <div align="left"></div> </div> <div></div></td> </tr>HTML_CODE;// DO NOT INDENT OR PUT ANYTHING ON THE LINE ABOVE}?>[/code]When using HEREDOC syntax you may need to wrap curly braces around your variable names ({$my_var}), especially if its an array. Quote Link to comment https://forums.phpfreaks.com/topic/28995-php-inside-html/#findComment-132865 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.