Jump to content

[SOLVED] echoing <div> tags in if statements.


seany123

Recommended Posts

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>;\";";
}
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/158158-solved-echoing-tags-in-if-statements/
Share on other sites

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

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>";
}

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.