tags:

views:

50

answers:

2

I need to search some information through mysql query,so can I write and or together?If not then what is the procedure?In my query it will show the either any one of the field or more than one field,so how can i write the query?rit now i am writing like:-

$query="select * from fsb_profile 
        where profile_name = '".$_REQUEST['name']."'  or
              profile_member= '".$_REQUEST['type']."'  or
              profile_year= '".$_REQUEST['year']."'  or
              profile_course='".$_REQUEST['course']."'";

but when i am filing all the field then it is like:-

$query="select * from fsb_profile 
        where profile_name = '".$_REQUEST['name']."' and 
              profile_member= '".$_REQUEST['type']."' and 
              profile_year= '".$_REQUEST['year']."' and
              profile_course='".$_REQUEST['course']."'";

but here it is not being possible to search by more than 1 field,is it mandatory to write the different query?or i can make it in one query,and how???

A: 

You can mix the AND or OR logic with brackets ().

You can also use the IN for multiple OR logics.

select * from table where 1 in (1,2,3)

Also you should read about SQL Injection

Pentium10
A: 

i didn't understand what you are actually asking... but i think your are looking for nested query..... like the following.....

SELECT * FROM t1  WHERE 2 = (SELECT COUNT(*) FROM t1);
Jaison Justus