Results 1 to 5 of 5

Thread: Search form (show/hide)

  1. #1

    3boxes Search form (show/hide)

    Hello,

    I created a search function on my website that works fantastic but I would like to add an extra option.

    I use this search function to search into a product database. Sometimes it happens that a product is temporarily not available and so i would like to hide this in the search results.

    I would like to add an extra field "hide" in my table with the value "yes" or "no", how can i tell my search script that it only must show the results with the hide value to "no" ?

    PHP Code:
              <?php
              mysql_connect
    ("localhost","**********","**********");
              
    mysql_select_db("**********");
              
    $search $_POST["search"];
              
    $search mysql_real_escape_string($search);
              
    $result mysql_query("SELECT * FROM articles_shop WHERE brand LIKE '%" $search "%' or type LIKE '%" $search "%'");                    if($search == ""){
              print 
    "please enter something";
              }else{
              if(
    mysql_num_rows($result) > 0) {
              while(
    $r=mysql_fetch_array($result)) {
              
    $brand $r["brand"];
              
    $type $r["type"];
              print 
    "$brand $type<br><br>";
              }      
              } else {
              print 
    "Nothing found";
              }
              }
              
    ?>

  2. #2
    PHP Code:
    mysql_query("SELECT * FROM articles_shop WHERE brand LIKE '%" $search "%' or type LIKE '%" $search "%' AND hide = 'no'"); 
    tho you should use boolean values... so it should be

    hide = 0
    hide = 1

    0 meaning "no"
    1 meaning "yes"

    PHP Code:
    mysql_query("SELECT * FROM articles_shop WHERE brand LIKE '%" $search "%' or type LIKE '%" $search "%' AND hide = 0"); 
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  3. #3
    Hellow,

    Thanks simplistik, it works (sometimes), its kind of strange.

    I followed your advice and created this code

    PHP Code:
    $result mysql_query("SELECT * FROM article_shop WHERE specification LIKE '%" $search "%' or descriptionLIKE '%" $search "%' or type LIKE '%" $search "%' or vero LIKE '%" $search "%' or brand LIKE '%" $search "%' AND hide = 'no'"); 
    This code works great but ...

    When I search for example for a "nokia" gsm and the word "nokia" is mentioned in the field "specification" then it will be found in the searchresults.

    If the word "nokia" is mentioned in the field "brand" and not in the the field "specification" then it will not be shown, thats good.

    What could this be?

    I already changed the order (first specification, last specifiaction, in the middle) but that didn't changed helped.
    Last edited by stedem; January 14th, 2008 at 05:30 PM.

  4. #4
    I don't think I follow... you're searching for a word and you're mad that it returns when you search for it?

    this is messed up
    Code:
    descriptionLIKE
    try this
    PHP Code:
    result mysql_query("SELECT * FROM article_shop WHERE ( specification LIKE '%" $search "%' OR description LIKE '%" $search "%' OR type LIKE '%" $search "%' OR vero LIKE '%" $search "%' OR brand LIKE '%" $search "%' ) AND hide = 'no'"); 
    Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
    Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.

  5. #5
    Hooray for simplistik , my hero

    Omg, looks like i made myself idiot again, just a stupid ( &)

    The main concept is that a product in the database that is hidden isn't allowed to show when its hidden (even if you search for it in the search box). It must be hidden all the time. (sound logic )

    The problem was that i tried to search a word for example nokia (and this product was hidden) and *surprise* it showed up

    Now the problem is fixed i can start to hide my stuff.

    Thanks again!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012