Hi All,

Am pretty newbie to php and am battling with a piece of code and just dont know what I am doing wrong.
I have a set of tabs along the top of my page with differnet user levels. If a user is an admin then they get to see different tabs.
I have this one tab as an example which allows an admin to send a newsletter and am attempting to make the tab visible.

<?php
        if($staff['isadmin'] == "1"){
        echo
            "<td width=\"104\" class="; if(!isset($_GET['section']) || $_GET['section'] == "newsletter") echo "tabactive"; else echo "tabinactive"; ">"; echo"<div align=\"center\"><a href=\"index.php?section=newsletter\" class="; if ($_GET['section'] == "newsletter") echo "tabactive"; else echo "tabinactive"; ">"; echo"Newsletter</a></div></td>";
             }
    ?>

What I am seeing is a blank tab where the word NEWSLETTER should appear. Have tried various permutations but have to say I am getting nowhere.. is there someone that can point me right here??

The expected value for $staff['isadmin'] is a boolean true/false or a string? If it's a boolean then change it to:

if($staff['isadmin'] === 1)

If you have doubts use var_dump($staff['isadmin']); to get the type of value.

Many thanks Cereal.. I learnt something new today :) The var_dump says its a string so I think I had that part correct ... I am thinking is has to be something in the echo statement that I have messed up

I have it sorted thanks... was incorrect syntax in the echo statment..
reworked code now looks like this.

<?php var_dump($staff['isadmin']);
        if($staff['isadmin'] == "1"){
        echo
            "<td width=\"104\" class="; if(!isset($_GET['section']) || $_GET['section'] == "newsletter") echo "tabactive"; else echo 

"tabinactive"; ">"; echo"<div align=\"center\"><a href=\"index.php?section=newsletter\" class="; if ($_GET['section'] == "newsletter") echo "tabactive"; 

else echo "tabinactive";echo">Newsletter</a></div></td>";
    }
    ?>

Thanks a lot though for taking the time to repsond to my query.. it helped me narrow down where the error was more likely to be...

Probably yes, use curly brackets to delimit the statements:

Do it like this:

echo "<td width=\"104\" class=";

if(!isset($_GET['section']) || $_GET['section'] == "newsletter")
{
    echo "tabactive";
}
else
{
    echo "tabinactive";
}
echo ">";

or simply:

echo '<td width="104" class="'.(!isset(GET_['section']) || $_GET['section'] == 'newsletter' ? 'tabactive':'tabinactive').'">;

The same goes for the other block of code:

echo "<div align=\"center\"><a href=\"index.php?section=newsletter\" class=";

if($_GET['section'] == "newsletter")
{
    echo "tabactive";
}
else
{
    echo "tabinactive";
}
echo ">";

echo "Newsletter</a></div></td>";

That becomes:

echo '<div align="center"><a href="index.php?section=newsletter" class="'.($_GET['section'] == "newsletter" ? 'tabactive':'tabinactive').'">Newsletter</a></div></td>';

EDIT
glad to see that you solved by yourself, bye! ;D

I have it sorted thanks... was incorrect syntax in the echo statment..
reworked code now looks like this.

<?php var_dump($staff['isadmin']);
        if($staff['isadmin'] == "1"){
        echo
            "<td width=\"104\" class="; if(!isset($_GET['section']) || $_GET['section'] == "newsletter") echo "tabactive"; else echo 

"tabinactive"; ">"; echo"<div align=\"center\"><a href=\"index.php?section=newsletter\" class="; if ($_GET['section'] == "newsletter") echo "tabactive"; 

else echo "tabinactive";echo">Newsletter</a></div></td>";
    }
    ?>

Thanks a lot though for taking the time to repsond to my query.. it helped me narrow down where the error was more likely to be...

Thanks cereal.. Now I have learnt something new again.. ;) I appreciate the time you take to help and advise newbies...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.