pixeltrace Posted March 11, 2007 Share Posted March 11, 2007 guys, i need help what codes do i need to use so that in my sql query i can search items WHERE lastname AND firstname LIKE '%". $_POST['name'] ."%'"; i have a form wherein you can search via the name of the person either using the first name or last name. but the query that i am using doesnt work and its giving me a (0) results whats wrong in my query codes? need help please thanks! Quote Link to comment https://forums.phpfreaks.com/topic/42203-need-help-on-query-codes/ Share on other sites More sharing options...
JasonLewis Posted March 11, 2007 Share Posted March 11, 2007 like this? $query = mysql_query("SELECT * FROM `table` WHERE `lastname` LIKE '%{$_POST['name']}%' OR `firstname` LIKE '%{$_POST['name']}%'") or die("Error: ".mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/42203-need-help-on-query-codes/#findComment-204719 Share on other sites More sharing options...
pixeltrace Posted March 11, 2007 Author Share Posted March 11, 2007 hi, this one is working if i type either the last name or first name but when i search typing both firstname and lastname on the search field its giving me a (0) result how do i fix this in such a way that if i also search using both firstname and last name i can still get the correct result. ex. if i search "juan pedro" or "juan" or "pedro" they will still give me juan pedro in my result thanks! Quote Link to comment https://forums.phpfreaks.com/topic/42203-need-help-on-query-codes/#findComment-204722 Share on other sites More sharing options...
JasonLewis Posted March 11, 2007 Share Posted March 11, 2007 my mysql isnt the greatest of all things, but what about checking if both fields are entered. run the a query to check for both the first and lastname else then run a query to check either the first or the last. not even sure that makes much sense. Quote Link to comment https://forums.phpfreaks.com/topic/42203-need-help-on-query-codes/#findComment-204724 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.