Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    149
    Thanks
    21
    Thanked 0 Times in 0 Posts

    If Query Statement

    I want a normal query to run unless an option is selected on the dropdown.

    I got

    PHP Code:
    if(!isset($_GET['nav'])) {
        
    $pricesQuery "SELECT * FROM tbl_prices ORDER BY prices_7,prices_1, prices_2";

    }else{
        
    $pricesquery"SELECT * FROM tbl_prices ORDER BY prices_7,prices_1, prices_2 WHERE "($_GET['nav'])"";

    I know I mangled the ($_GET.... part at the end. How should i put it?

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,038
    Thanks
    23
    Thanked 589 Times in 588 Posts
    if(!isset($_GET['nav'])) { produces an else statement how is that WHERE section getting info?

    Maybe this:
    PHP Code:
    <?php
    if(!empty($_GET['nav'])) {
        
    $thing $_GET["nav"];
        
    $pricesquery"SELECT * FROM tbl_prices ORDER BY prices_7,prices_1, prices_2 WHERE something = '$thing'";
    }else{
        
    $pricesQuery "SELECT * FROM tbl_prices ORDER BY prices_7,prices_1, prices_2";
    }
    ?>
    Evolution - The non-random survival of random variants.

  • #3
    Regular Coder
    Join Date
    Aug 2013
    Posts
    149
    Thanks
    21
    Thanked 0 Times in 0 Posts
    I have a link like

    <a href="index.php?nav=action">Action</a>

  • #4
    Regular Coder
    Join Date
    Aug 2013
    Posts
    149
    Thanks
    21
    Thanked 0 Times in 0 Posts
    But i see what you did there and that should work

  • #5
    Regular Coder
    Join Date
    Aug 2013
    Posts
    149
    Thanks
    21
    Thanked 0 Times in 0 Posts
    So this is what I got
    PHP Code:
    if(!empty($_GET['nav'])) {
        
    $thing $_GET["nav"];
        
    $pricesString"SELECT * FROM tbl_prices ORDER BY prices_7,prices_1, prices_2 WHERE prices_7 = '$thing'";
    }else{
        
    $pricesString "SELECT * FROM tbl_prices ORDER BY prices_7,prices_1, prices_2";
    }
        
    $pricesQuery mysql_query($pricesString); 
    I have a dropdown that I assigned values to that I was hoping would when selected go into "nav" and then change the query. What am I missing?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •