seany123 Posted May 14, 2009 Share Posted May 14, 2009 okay so what im wanting is for the 3 if statements below to be combined into the same div class... so instead of 3 seperate <div>s instead its all in 1. if($player->hospital >= 1) { echo "<div class="g_content"><h3> Notifications</h3><div class=\"g_text\"> <center><a href=\"../hospital.php\">You Are In Hospital [\" . $player->hospital . \"mins left]</a><br></center></div></div>;"; } ?> if($player->prison >= 1) { echo "<div class="g_content"><h3> Notifications</h3><div class=\"g_text\"> <center><a href=\"../prison.php\">You Are In Prison [\" . $player->prison . \"mins left]</a><br></center></div></div>;"; } ?> if($player->news >= 1) { echo "<div class="g_content"><h3> Notifications</h3><div class=\"g_text\"> <center><a href=\"../news.php\">You have unread News</a><br></center></div></div>;"; } ?> so instead of the above it would be something like this... <?php if($player->hospital >= 1 || $player->prison >= 1 || $player->news >= 1) { echo "<div class="g_content"><h3> Notifications</h3><div class=\"g_text\">"; if(player->hospital >= 1) { echo "<center><a href=\"../hospital.php\">You Are In Hospital [\" . $player->hospital . \"mins left]</a><br></center>"; } if(player->prison >= 1) { echo "<center><a href=\"../prison.php\">You Are In Prison [\" . $player->prison . \"mins left]</a><br></center>"; } if(player->news >= 1) { echo "<center><a href=\"../news.php\">You have unread News</a><br></center>"; } echo "</div></div>;\";"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/158158-solved-echoing-tags-in-if-statements/ Share on other sites More sharing options...
wildteen88 Posted May 14, 2009 Share Posted May 14, 2009 You need to escape the double quotes within your strings. Otherwise PHP will think you're ending the string early echo "<div class=\"g_content\"><h3> Notifications</h3><div class=\"g_text\">"; Quote Link to comment https://forums.phpfreaks.com/topic/158158-solved-echoing-tags-in-if-statements/#findComment-834242 Share on other sites More sharing options...
seany123 Posted May 14, 2009 Author Share Posted May 14, 2009 so something like this?? <?php if($player->hospital >= 1 || $player->prison >= 1 || $player->news >= 1) { echo "<div class=\"g_content\"><h3> Notifications</h3><div class=\"g_text\">"; if(player->hospital >= 1) { echo "<center><a href=\"../hospital.php\">You Are In Hospital [\" . $player->hospital . \"mins left]</a><br></center>"; } if(player->prison >= 1) { echo "<center><a href=\"../prison.php\">You Are In Prison [\" . $player->prison . \"mins left]</a><br></center>"; } if(player->news >= 1) { echo "<center><a href=\"../news.php\">You have unread News</a><br></center>"; } echo "</div></div>;\";"; } } ?> this doesnt look right at all echo "</div></div>;\";"; the other problem i might have is that this php code itself is inside a set of <div> tags Quote Link to comment https://forums.phpfreaks.com/topic/158158-solved-echoing-tags-in-if-statements/#findComment-834249 Share on other sites More sharing options...
wildteen88 Posted May 14, 2009 Share Posted May 14, 2009 This line echo "</div></div>;\";"; should be outside of your last if statement. if($player->hospital >= 1 || $player->prison >= 1 || $player->news >= 1) { echo "<div class=\"g_content\"><h3> Notifications</h3><div class=\"g_text\"><center>"; if($player->hospital >= 1) { echo "<a href=\"../hospital.php\">You Are In Hospital [\" . $player->hospital . \"mins left]</a><br>"; } if($player->prison >= 1) { echo "<a href=\"../prison.php\">You Are In Prison [\" . $player->prison . \"mins left]</a><br>"; } if($player->news >= 1) { echo "<a href=\"../news.php\">You have unread News</a><br>"; } echo "</center></div></div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/158158-solved-echoing-tags-in-if-statements/#findComment-834252 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.