hi.. your should just use if (empty($foo)) statements.. i did my search scripts like that too and they were wonderful! PS: besides $query, all the $variables are being posted from a form... $query = "select * from myTable where "; $query .= (!empty($typeS)) ? "Column1 = '$typeS' and " : ""; $query .= (!empty($salesmnS)) ? "Column2 = '$salesmnS' and " : ""; $query .= (!empty($agtCdS)) ? "Column3 like '$agtCdS%' and " : ""; $query .= (!empty($tourNmS)) ? "Column4 like '%$tourNmS%' and " : ""; $query .= (!empty($dtFromS)) ? "Column5 >= '$dtFromS' and " : ""; $query .= (!empty($dtToS)) ? "Column6 <= '$dtToS' and " : ""; $query .= " T01Br = '$branch' "; $query .= " group by T01RefNo order by T01InDt desc"; a few things to note: you should be careful with the "and".. a trick is to place a compulsory search field at the end of the query. you should also be careful to give _spaces_ " " ... hth -------- Original message ----- > > > >> Nabil wrote: > > > >> > > > >> > hi all.... > > > >> > > > > >> > Is there a way to condition your search: > > > >> > > > > >> > -I have a form for four text boxes for search my Mysql... > > > >> > -I don't want to write 4 conditions and for SQL statements > > > >> > incase he decided not to search with all keywords (fields) > > > >> > - I have by example : name, lastname , nickname and phone > > > >> >form... I need a way to select my records even one or more field were > > > >> > null (searching only on of the above) > > > >> > > > > >> > because the following SQL will generate null result > > > >> > > > > >> > > > > >> > $name=$_POST['naame']; > > > >> > $lastname=$_POST['lastname']; > > > >> > $nickname=$_POST['nickname']; > > > >> > $m_date=$_POST['m_dateY']; > > > >> > echo $name.$lastname.$nickname.$m_date; > > > >> > > > > >> > "SELECT id, name , lastname , m_date from users > > > >> > where > > > >> > name like binary '%$name%' and lastname like binary > '%$lastname%' and > > > >> > nickname like binary '%$nickname%' and m_date= YEAR('$m_date') > > > >> > order by id ASC ") or die(mysql_error()); > > > >> > > > > >> > Thanks in advanced -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php