davidz Posted April 5, 2007 Share Posted April 5, 2007 I have a search page that queries a database and my users are used to using "*" (asterisks) for wildcard searching. Mysql on the other hand uses "%" percent signs. Is there a simpler way besides looking through their search item and replacing any * with %? Or is this the recommended method? Thanks! Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/ Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 You lost me.. ??? Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/#findComment-222477 Share on other sites More sharing options...
effigy Posted April 5, 2007 Share Posted April 5, 2007 Would FULLTEXT work, or do you require wildcards? Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/#findComment-222482 Share on other sites More sharing options...
davidz Posted April 5, 2007 Author Share Posted April 5, 2007 Sorry if I was too vague. For example, you type bob* into a search box expecting to find results like bob, bobby, bobbie, bobble, etc. But mysql does not use *'s they use %'s so you query should look like SELECT * FROM WordList WHERE username like 'bob%'; So I am wondering if there is a simple way to do this. Or if doing a str_replace is the best method. Thanks! Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/#findComment-222485 Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 is most cases i filter out the * and when using like i use the following:~ "SELECT * FROM WordList WHERE username like '%".$search."%';" Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/#findComment-222488 Share on other sites More sharing options...
davidz Posted April 5, 2007 Author Share Posted April 5, 2007 Would FULLTEXT work, or do you require wildcards? I need wildcards. is most cases i filter out the * and when using like i use the following:~ "SELECT * FROM WordList WHERE username like '%".$search."%';" This is how I used to have it, but the queries were too slow with the leading %. The table has over almost half a million records, so I don't want any wildcards unless the user puts them in explicitly (this way they expect it to be slower). But if I know what I'm looking for and type it in exactly it queries instantly without the wildcards. Thanks for the all the input! Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/#findComment-222514 Share on other sites More sharing options...
Azu Posted April 5, 2007 Share Posted April 5, 2007 If I were you I'd either use str_replace to just escape the %s and then replace * with % OR have it search for an exact match, and then search for it with wildcards only if it doesn't find it. Link to comment https://forums.phpfreaks.com/topic/45795-using-a-asterisk-in-a-mysql-query/#findComment-222519 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.