ntroycondo Posted September 3, 2010 Share Posted September 3, 2010 I have a form passing user's search term, ie name. $pname = mysql_real_escape_string($pname; Not sure on proper syntax to include this in my select statement. I also want it to return for partial string matched, like 'mik' for 'mike': $result = mysql_query( "SELECT * FROM guest WHERE name like '$pname'" ); Link to comment https://forums.phpfreaks.com/topic/212443-searching-mysql-with-form-variable/ Share on other sites More sharing options...
muzzs Posted September 3, 2010 Share Posted September 3, 2010 Hi ntroycondo, This is a MySQL question really and so is in the wrong forum. What you need to use to get the desired result is the MySQL wildcard character (%), when this is used with the LIKE keyword, it is a wildcard for 0 or any number of characters. E.g. if you wanted it to allow partial strings that all start with the correct letters you will want: $result = mysql_query( "SELECT * FROM guest WHERE name like '$pname%'" ); Hope that helps! Link to comment https://forums.phpfreaks.com/topic/212443-searching-mysql-with-form-variable/#findComment-1106903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.