#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    4
    Rep Power
    0
    Hi, I have a pull down box that sends the variable $sort, if the value of sort is 1, I want it to run a certain sql query but if the value is 2, I want it to run a different query. I've been using:

    if ($sort==1)
    { sql stuff }
    elseif ($sort==2)
    { sql stuff }
    else
    { run a default query }

    for some reason every time the script runs, it always does the case for $sort==1. Any help would be appreciated. Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    14
    You must check is you are submitting the form i.e if $sort value is passed or not through submit button as u are using a dropdown menu. If u are submitting the form check if the value of the sort is passed to the file which is checking for its value. I this even is not the case then u can use some thing like this whick should work:

    Ur code:
    if($sort==1)
    {
    $sql="Select * from mytable";
    }
    if($sort==2)
    {
    $sql="Select * from urtable";
    }
    $result=mysql_query($sql);
    $row=mysql_fetch_array($result);
    etc...
    blah..blah...

    ------------------
    Nikunj Virani
    MYSQL/PHP/XML
    This is the world of Nikunj
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    4
    Rep Power
    0
    Yep, the $sort variabl is being passed, I cheacked by doing an echo "$sortn"; after each if statement. The realy problem is that it seems as if the default is fro $sort=1...it never actually runs the else { default } stuff.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Pune, Maharashtra, India
    Posts
    86
    Rep Power
    14
    I cannot help much without seeing the script but it seems that there may be one reason that u r using '=' instead of '==' .You even didn't tell that what did echo($sort) gave is it always '1' if so a possible cause may be in the <option value=""> tag used during making of the dropdown menu.Sorry no more help till I can see the script. Bacause most possible ans. are listed here already.

    ------------------
    Nikunj Virani
    MYSQL/PHP/XML
    This is the world of Nikunj
  8. #5
  9. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    As nikunj said check wether your $sort value is passing properly or not...

    try this:
    <?
    echo $sort;
    if ($sort=="1"){
    sql stuff
    }elseif ($sort=="2"){
    sql stuff
    }else{
    run a default query
    }
    ?>



    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. Passing POST variables
    By rlorenzo in forum PHP Development
    Replies: 11
    Last Post: June 6th, 2004, 02:00 PM
  2. help with assigning variables, variable passing/ retrieval
    By pinkipodmini in forum PHP Development
    Replies: 0
    Last Post: February 13th, 2004, 09:40 PM
  3. Replies: 2
    Last Post: February 10th, 2004, 11:03 PM
  4. losing session variables
    By shawazi in forum PHP Development
    Replies: 1
    Last Post: January 27th, 2004, 12:02 PM
  5. How to get multiple sessions for one user working?
    By jkoerber in forum PHP Development
    Replies: 1
    Last Post: January 16th, 2004, 01:23 PM

IMN logo majestic logo threadwatch logo seochat tools logo