Question:

How do you get a PHP if statment in a Variable

by  |  earlier

0 LIKES UnLike

Hi

I'm trying to get a if statement into a variable so that the variable is dynamic to what is int the $_GET['mode'] variable. If this isnt possible how would it be possible to put a if statement into a MYSQL query. I'm currently trying to set up a message page that will give the users two tabs that are Inbox and Outbox the modes will be 'i' and 'o' respectively.

Thanks

Ali

 Tags:

   Report

2 ANSWERS


  1. $folder = ($_GET['mode']=='inbox'?'i':'o');

    //folder variable is "i" if mode is inbox, otherwise "o"

    or

    $query = 'SELECT * FROM mailbox where folder="'. ($_GET['mode']=='inbox'?'i':'o') .'"';


  2. if($_GET[mode] == "i"){

    //whatever you want to do

    }

    elseif($_GET[mode] == "o"){

    //the alternative.

    }

    Better would be 2 submit buttons named inbox and outbox :

    <input type='submit' name='inbox' value='Inbox' />

    <input type ='submit' name='outbox' value='Outbox' />

    Then use (post is better)

    if ($_POST[inbox]){

    //your inbox code

    }

    elseif($_POST[outbox]){

    //your outbox code

    }

    Your code then accesses the location.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.