Combination of field search using PHP & MYSQL

后端 未结 3 855
长情又很酷
长情又很酷 2020-12-22 06:39

I am working on an assignment using PHP & MYSQL.

one of the tasks is to search on any combination of the fields. That includes Dropdown boxes populated from the

3条回答
  •  暖寄归人
    2020-12-22 06:55

    Why not evaluate your string with each column (this is a guide only, I'm not building your PHP code there:

    SELECT 
      * 
    FROM 
      table
    WHERE 
      (ID = $id OR $id = 'showAll')
      AND (SPORT = $sport OR $sport = 'showAll')
      AND (COUNTRY = $country OR $country = 'showAll')
      AND (GENDER = $gender OR $gender = 'showAll')
      AND (FIRSTNAME = $firstname OR $firstname = 'showAll')
    

    Just need to make sure you NVL the variables to an appropriate value (whether it be int or string)

提交回复
热议问题