In my database i have one column for first name and last name.
In my code i have combined this two columns and used it as full name.
i have one search box in the display which looks like this,

the code for the searching is like,
switch($search_by){
case "fullname":
$sql_where_clause = "fname like '".$search_keyword."%';
break;
case "user_name":
$sql_where_clause = "uname like '".$search_keyword."%';
break;
}
and this $sql_where_clause is used in the query for searching.
when i search for full name as arpi which is my first name in database it gives me perfect answer because i have done code for first name.
but the problem is, when i search as arpi patel where arpi is first name and patel is last name then search is not performed because i have not done code for that because i don’t know how to perform this.
does anyone know how to fire query for my first and last name columns together in the $sql_where_clause
You need to use logical operatores in your SQL query like this:
$sql_where_clause = "fname LIKE '$fname' AND uname LIKE '$uname'";How can you get $fname and $uname variables? If your $search_keyword looks like this:
family nameyou can explode it by space$search_parts = explode(' ', $search_keyword, 2). But in that case you do not know which part is the family and which is the name, so you have to perform query like that:$sql_where_clause = "(fname LIKE '${part[0]}' AND uname LIKE '${part[1]}') OR (fname LIKE '${part[1]}' AND uname LIKE '${part[0]}')";Btw, don’t forget to sanitize your queries against sql-injections. Bad way – use mysql_real_escape_string. Good and easy way – use PDO and prepaired queries.