MySql and PHP Query help

Discussion in 'PHP' started by OreoKnight, Feb 15, 2008.

  1. #1
    So here is my problem, I am creating categories for my website; however, I don't want all the categories to show up under my left nav bar, just a few select ones. Is there a way I could change this code to pick certain category ids, say 30 , 31, 33, and 35 to only show up? Your help is greatly appreciated!

    <?

    // get categories

    $sql = mysql_query("select * from categories where id != 1");

    $count = mysql_num_rows($sql);

    if($count > 0){

    while($row = mysql_fetch_assoc($sql)){

    $name = $row['name'];

    print ''.$name.'';

    }

    }

    else{

    print 'There are currently 0 categories. Please login to your admin panel to manage categories.';

    }

    ?>
     
    OreoKnight, Feb 15, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Replace the first line with this:
    
    $sql = mysql_query("select * from categories where id IN(30, 31, 33, 35)") OR die(mysql_error());
    
    PHP:
     
    nico_swd, Feb 15, 2008 IP
  3. OreoKnight

    OreoKnight Peon

    Messages:
    95
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    DUDE!!!! You rock, thanks a ton.
     
    OreoKnight, Feb 15, 2008 IP