0

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??

2
Contributors
6
Replies
19
Views
4 Years
Discussion Span
Last Post by garwil
0

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.

0

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

0

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...

0

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

Edited by cereal

0

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...

1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.