A-SAP help please!

Discussion in 'PHP' started by le007, Sep 26, 2007.

  1. #1
    Hi all,

    I'm trying to get only certain results from a search I've written. The problem is I have 2 separate search pages.

    1st searches for specific features that are in a "feature_type" dropdown menu eg
    all colours
    colour red
    colour yellow
    colour green
    colour blue
    colour white
    colour purple

    2nd searches for other specific features that are in the SAME dropdown menu but I have limited their search options to just be:
    all colours
    colour red
    colour green

    The problem is: when the user leaves "all colours" selected in the dropdown menu and clicks search ALL the colours come up in both search result pages.

    What I'd like is if they hit "all colours" in the first search that just yellow, green, blue, white and purple would show up.

    In the 2nd if they click "all colours" that ONLY colour red and colour green would show up.

    ANY help? I've tried if's and cases etc...

    How could I have something like if feature_type = "colour white" then don't include it in the result?

    Thanks
     
    le007, Sep 26, 2007 IP
  2. hemlata

    hemlata Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello,

    What query you are using to search for 'all_colors' or for any specific color?

    Regards,
     
    hemlata, Sep 26, 2007 IP
  3. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Hi Hemlata,

    $sql = "SELECT * FROM `tabel` WHERE `colour_type` like '$colour_type' >
    $sirsql = mysql_query($sql) or die(mysql_error());
     
    le007, Sep 27, 2007 IP
  4. sabmalik

    sabmalik Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    for second page.
    modify the search
    if($page == 2){
    if($color_all){
    $q = "select * from `table` WHERE `color_type` LIKE 'red' OR `color_type` LIKE 'green' ";
    }
    }
     
    sabmalik, Sep 27, 2007 IP
  5. hemlata

    hemlata Peon

    Messages:
    18
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hello le007,

    Use sqls as..

    
    $all_color = array();
    if ($page == 'page1')
    {
    	$all_color = array('red', 'yellow', 'green', 'blue', 'white', 'purple');
    }
    else if ($page == 'page2')
    {
    	$all_color = array('red', 'green');
    }
    
    $sql = "SELECT * FROM `tabel` WHERE `colour_type` IN('".implode(', ', $all_color)."') ";
    $sirsql = mysql_query($sql) or die(mysql_error());
    
    Code (markup):
    Hope this will solve your issue.
    Regards,
     
    hemlata, Sep 28, 2007 IP
  6. sabmalik

    sabmalik Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    that is a really decent way of doing it , comprehensive solution :)
     
    sabmalik, Sep 28, 2007 IP