php if else statement help needed!

Discussion in 'PHP' started by netpox, Sep 12, 2007.

  1. #1
    Here is my code:

    <?php if($CFG['admin']['is_logged_in']){?>
    <a href="<?php echo $CFG['site']['url'].'admin/';?>">Admin</a>
    <?php }?>


    If i'm logged in as admin it shows a link where i can click on the Admin and go to the admin panel. I want it to have an else statement.

    So if you're not logged in then it shows a different link. What would i write?
     
    netpox, Sep 12, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php if($CFG['admin']['is_logged_in'])
    {
    ?>
    <a href="<?php echo $CFG['site']['url'].'admin/';?>">Admin</a>
    <?php 
    }
    else
    {
    ?>
    <a href="file.html">link</a>
    <?php
    }
    ?>
    
    PHP:
     
    nico_swd, Sep 12, 2007 IP
  3. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <? if($CFG['admin']['is_logged_in']){?>
    <a href="<?=$CFG['site']['url'];?>/admin/';?>">Admin</a>
    <?}else{?>
    <a href="<?=$CFG['site']['url'];?>/NONadmin/';?>">NonAdmin</a>
    <?}?>
     
    vonvhen, Sep 13, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I guess you didn't like my solution, lol. :rolleyes:
     
    nico_swd, Sep 13, 2007 IP
  5. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    LOL it is basically the same things ;-)
     
    vonvhen, Sep 13, 2007 IP
  6. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Is doing it this way better than one set of tags echoing the html?
     
    Synchronium, Sep 13, 2007 IP
  7. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    It depends on your web application. Sometimes, you have no choice but to echo the html code.
     
    vonvhen, Sep 14, 2007 IP
  8. netpox

    netpox Active Member

    Messages:
    1,625
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    90
    #8
    Cool thanks guys! I will try this now.
     
    netpox, Sep 14, 2007 IP