Author Topic: [SOLVED] If...else not working ???  (Read 515 times)

0 Members and 1 Guest are viewing this topic.

Offline ~n[EO]n~Topic starter

  • Devotee
  • Posts: 725
    • View Profile
[SOLVED] If...else not working ???
« on: October 01, 2007, 06:53:23 AM »
Hi all ;

I got a page (index.php) where i have included naigation (menu.php) file, what i was trying to do is while the  user is in current page change the CSS of that navigation link.

I did this but if..else condition is not working, Can someone have a look please...

in the index.php file I kept

Code: [Select]
<?php
$indexclassic 
1;

?>

in this page i have included the menu file
Code: [Select]
<?php include("include/menu_classic.php"); ?>
and in menu_classic.php what i did was

Code: [Select]
<tr>
<?php if(isset($indexclassic)) { ?>
                          <td class="classic_on">Home</td>
<? }
else
{
?>
<td><a href="accueil_classic.php" class="classic">Home</a></td>
<?php 
 } 
 ?>

                        </tr>

This works, but both the Home link comes 2 times, one from if condition and other from else condition.

Can someone guide me, please...



Offline mgallforever

  • Addict
  • Posts: 1,760
  • Gender: Male
  • once upon a time
    • View Profile
    • PHPSquad
Re: If...else not working ???
« Reply #1 on: October 01, 2007, 06:55:23 AM »
Try setting the variable equal to TRUE.


$indexclassic 
TRUE;


Then just check if it's true:

if($indexclassic){
echo 
"do this"//true
}else {
echo 
"do something else"//false
}
http://youtube.com/phpsquad :: http://phpsquad.net
-Marcus Recck :: 19 yrs old-

Offline ~n[EO]n~Topic starter

  • Devotee
  • Posts: 725
    • View Profile
Re: If...else not working ???
« Reply #2 on: October 01, 2007, 07:05:56 AM »
Sorry this didn't work out  :(

Offline shocker-z

  • Devotee
  • Posts: 1,257
    • View Profile
Re: If...else not working ???
« Reply #3 on: October 01, 2007, 07:12:30 AM »
try using full php tags

Code: [Select]
<tr>
<?php if(isset($indexclassic)) { ?>
<td class="classic_on">Home</td>
<?php 
} else {
 
?>

<td><a href="accueil_classic.php" class="classic">Home</a></td>
<?php 

?>

</tr>

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

Offline ~n[EO]n~Topic starter

  • Devotee
  • Posts: 725
    • View Profile
Re: If...else not working ???
« Reply #4 on: October 01, 2007, 07:18:22 AM »
Thanks a lot man... it worked now.. ;)