How to do Multiple Condition in SQL query using PHP and Ajax

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 11
Joined: Fri Jul 27, 2012 9:52 am

Mon Apr 08, 2013 11:13 pm


I have databse in MySQL with 21 fields which are listed below
Field Name Data Type NULL
status text No
roll_no text No
branch_id int(5) No
student_name text No
father_name text No
phone1 text No
phone2 text No
email text No
dob date No
city text No
course_id varchar(5) No
class_id int(2) No
program text No
duration text No
comment text No
admission_year int(4) No
admission_date text No
entryby text No
address text No
admission_no int(4) No
fees int(6) No

Now I am stuck with search process, I bit confused, how can I perform search for different types of conditions/criteria

Few Examples of combinations of condtions
1. Only those records of city=3
2. Only those branch_id=2
3. Only those admission_year='2013'
4. Only those course_id='15'
5. Only those branch_id='2' AND course_id='15'
6. Only those branch_id='2' AND course_id='15' AND city LIKE 'XYZ'
7. Only those admission_year='2012' AND course_id='10' AND duration BETWEEN(2 AND 3)
8. Only those branch_id=2 AND course_id='15' AND student_name LIKE 'XYZ'
8. Only those course_id=7 AND class_id=2 AND father_name LIKE 'XYZ'

My search.php form page is designed, I uploaded the image of form design here but I am confused how can I implement this search options for different situations.

Please give me some guidance and show me the correct way to solve this issue.

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Tue Apr 09, 2013 2:29 am

What are you confused at? Just write the SQL.

php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Tue Apr 09, 2013 10:43 pm

Helping you would be so much easier if you listed some of your code, but johnj is as usual right on the money. There are a lot of ways to do what you're trying to do, but in every one of them you need to understand how to generate a safe sql query (the safe part is key) then get it to the database and process the result. Here is a short video on using PDO so you can see some general database interactions done correctly, and then you can write up some specific code that we can help with . ... o-examples

New php-forum User
New php-forum User
Posts: 72
Joined: Wed Jun 12, 2013 9:30 pm

Fri Jun 14, 2013 1:02 am

You have to writ SQL queryby giving conditions. use and between two condition.

Post Reply