cksrealm Posted April 30, 2007 Share Posted April 30, 2007 Hi all, I have written a simple search scripts that searches a database based on a customers name and prints the output to a web browser, only issue is that the customer name has to be entered exactly as it appears in the database, is there anything that I can that will for example return the data if a user just enters say a and it will show all customer that start with a Hope you know what I mean Regards CK Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/ Share on other sites More sharing options...
suzzane2020 Posted April 30, 2007 Share Posted April 30, 2007 http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html check this out-Pattern Matching for eg if u need names containg or starting from a select * from table where name like ' %a%' will give u names containing the letter a Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241652 Share on other sites More sharing options...
monk.e.boy Posted April 30, 2007 Share Posted April 30, 2007 http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html SELECT * FROM people WHERE name LIKE 'a%' monk.e.boy Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241654 Share on other sites More sharing options...
monk.e.boy Posted April 30, 2007 Share Posted April 30, 2007 suzzane2020 - are you reading my thoughts? Scary. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241658 Share on other sites More sharing options...
suzzane2020 Posted April 30, 2007 Share Posted April 30, 2007 ha ha nw thts coincidence!!! Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241660 Share on other sites More sharing options...
cksrealm Posted April 30, 2007 Author Share Posted April 30, 2007 Guys thanks for your comments however its not as easy as you said, the current query looks like this mysql_query("SELECT number FROM customers WHERE custname='$custname'") the $custname is a value that is set within the search page, i.e the field that users input the customers name. Therefore I am unable to just take a single letter from it and search for that arent. Or am I just being a fool. Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241666 Share on other sites More sharing options...
monk.e.boy Posted April 30, 2007 Share Posted April 30, 2007 mysql_query("SELECT number FROM customers WHERE custname LIKE '$custname%'"); if that don't work try: mysql_query("SELECT number FROM customers WHERE custname LIKE '". $custname ."%'"); TAKE CARE OF ALL THE QUOTES I HAVE USED. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241676 Share on other sites More sharing options...
suzzane2020 Posted April 30, 2007 Share Posted April 30, 2007 The point is : watever the user inputs in the field will be taken and compared to wats there in te database so u dont have to take any letter from that I hope u got wat we were tryin to say Link to comment https://forums.phpfreaks.com/topic/49312-php-search-script/#findComment-241679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.