'Filter table from database by 2 filed and from 1 table

I learn about the script autodidact and only PHP and Mysql and i don't know how to tell the things about the name part of script or syntax or anything i just know how to use it and hard to for me find my question from google, please understand me, sorry.

There is possible to filter 2 field firstname and year from 1 database?

  • Condition 1 : When i type firstname by input only, it work, start from refresh first if not go to condition 3.
  • Condition 2 : When i select year by select option only, it work, start from refresf first if not go to condition 3.
  • Condition 3 : When i select year and type by input, it doesn't work.

What i need is, when i select year 2009 and than when i just type 'a' Abdul and Agus selected from database, should only abdul selected from database.

I think the problem is my PHP and Mysql so i focus on them

Here my database directory:

| firstname | status | year  |
|:--------- |:------:| :----:|
| Agus      | Alumni | 2008  |
| Abdul     | Alumni | 2009  |
| David     | Alumni | 2009  |
| Jelita    | Student|       |

and here is mysql query

$sql="SELECT * FROM directory where
status='Alumni' and year Like '%".$q."%' or
status='Alumni' and firstname Like '%".$q."%'";


Solution 1:[1]

sql = select * FROM `directory` where `year` = '$year' and `firstname` = '$firstname%'
where $year = '2009' and $firstname = 'a'

this will output

firstname status year
Abdul Alumni 2009

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 PM 77-1