justAnoob Posted December 2, 2009 Share Posted December 2, 2009 I have a little search script. But I also want it to search for the plural of words also ex: guitar guitars or crash crashes Basically adding either "s" and "es" to any word entered in the search box. The question I got is, what is the name for adding letters to variables? I think I can figure it out if I know what to look for. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/ Share on other sites More sharing options...
Gayner Posted December 2, 2009 Share Posted December 2, 2009 I have a little search script. But I also want it to search for the plural of words also ex: guitar guitars or crash crashes Basically adding either "s" and "es" to any word entered in the search box. The question I got is, what is the name for adding letters to variables? I think I can figure it out if I know what to look for. str replace google it Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969400 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 thank you. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969404 Share on other sites More sharing options...
mikesta707 Posted December 2, 2009 Share Posted December 2, 2009 I think OP meant concatenation. adding a small amount of characters (or a large amount) to a string is called concatenation. $string = "pumpkin"; $plural = $string."s"; is that what you meant Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969411 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 I think so, I just need to create another variable off of the first one so my search script will search for the plural also. I'll do some playing around. I think the only problem I may run into is if I already type the plural into the search box, then I need it to check for the singular tense of the word. Any input would be greatly accepted. But in the meantime, its coding time(more like trial and error for me, lol) Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969416 Share on other sites More sharing options...
blueman378 Posted December 2, 2009 Share Posted December 2, 2009 it seems to be that you are going to try to make almost a database of plural form words, would it not be better to use like? eg in your query have LIKE 'crash%' that would return crash, crashed, crashing, crashn (for those who like to abbreviate) ect Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969418 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 Here is my query now. <?php $var = @$_GET['whatever'] ; $trimmed = trim($var); $query = "select * from MYTABLE where SOMETHING like \"%$trimmed%\" or description like \"%$trimmed%\" order by SOMETHING"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969425 Share on other sites More sharing options...
blueman378 Posted December 2, 2009 Share Posted December 2, 2009 your where c;ause is malformed, it needs to be where columnname=columnvalue Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969436 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 Now I'm confused. Someone told me(this person says they have been coding for a long time) when I use LIKE, that I shouldn't use the "=". How would you have it. Any other opinions would be great. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969440 Share on other sites More sharing options...
blueman378 Posted December 2, 2009 Share Posted December 2, 2009 sorry ignore my last post Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969444 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 it seems to be that you are going to try to make almost a database of plural form words, would it not be better to use like? eg in your query have LIKE 'crash%' that would return crash, crashed, crashing, crashn (for those who like to abbreviate) ect So my query, <?php $var = @$_GET['whatever'] ; $trimmed = trim($var); $query = "select * from MYTABLE where SOMETHING like \"%$trimmed%\" or SOMETHING like \"%$trimmed%\" order by ID"; ?> lets say I have the word "guitar" in my database, with this code, it will not return a result when i enter in "guitars" only if i enter "guitar". Didn't you say that it should return a result or is the query still wrong? Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969453 Share on other sites More sharing options...
blueman378 Posted December 2, 2009 Share Posted December 2, 2009 why do you need this part? or SOMETHING like \"%$trimmed%\" and yes you are correct, in general searches like this are built upon the logic that people will not search for plurals if they want the singular. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969459 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 "SOMETHING" is the column in my database where I want my search to look for matches with my $trimmed var. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969468 Share on other sites More sharing options...
mikesta707 Posted December 2, 2009 Share Posted December 2, 2009 Something like '%$trimmed%' will match to the word, and the word inside anything. so if you searched guitar, it would return guitars, bass guitar, electric guitars, etc. The % is a wildcard, and since you apply it to both sides, it means that anything could be next to the search term. If you want just the word, and like plural variations, and stuff like that, '$trimmer%' might work. That would match a search of guitar with guitar, guitars. However, watch out for abnormal english words where the plural is different from the singular Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969473 Share on other sites More sharing options...
blueman378 Posted December 2, 2009 Share Posted December 2, 2009 im refering to how you are repeating yourself where SOMETHING like \"%$trimmed%\" or SOMETHING like \"%$trimmed%\" do you need the or? Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969477 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 I wanted to search 2 different columns in the database, an name and description . I just put something and something in there as an example. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969490 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 I was searching 2 different columns in the database, name and description columns, something and something were just rough examples. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969491 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 ooppss, double reply. do you mean something like this. <?php $query = "select * from MYTABLE where SOMETHING like \"$trimmed%\" or SOMETHING like \"$trimmed%\" order by ID"; ?> Just take out the first % ? That only allows me to retrieve the exact word if it is the first word. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969494 Share on other sites More sharing options...
blueman378 Posted December 2, 2009 Share Posted December 2, 2009 ah i see what you are doing now, the somethings would be replaced later by eg title and contents. fair enough. but as i said basically search things do not cater in general for searching guitars to try and find guitar, then simplest approach is to have a note to users informing them that searching for guitar will search for guitar, guitars, guitarist ect may i suggest this as a tutorial for you as you seem to want to build your search up. http://iamcal.com/publish/articles/php/search/ Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969497 Share on other sites More sharing options...
mikesta707 Posted December 2, 2009 Share Posted December 2, 2009 I don't know what your data looks like, so I can't tell you what your query should be. If you want to match any columns with the word inside of it, then use '%$var%' if you just want to match different endings (IE match to the beginning of the word) use '$var%'. If you want to match the end of the word, use '%$var' Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969498 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 I won't keep going on about this subject, just one last thing to mention. Here is an example of a name and description in the database Name: 1965 Gibson SG Electric Guitar Description: rare 1965 gibson sg electric guitar. original owner. frets have pearl inlays. in very good condition with only minor scratches. plays great with no string buzz. Now when I type in "guitar" in the search box, 65 Gibson is given to me as a result. (Nice!) If I were to type in "guitars" in the search, i get no results (bad) Also, if I were to type in "guita", the 65 Gibson is a result (still nice) Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969507 Share on other sites More sharing options...
mikesta707 Posted December 2, 2009 Share Posted December 2, 2009 thats because the words "guitars" isn't in the name or description. You have a multitude of options. You can add a tags column to your DB, so you can put different tags in (like guitar, guitars, etc) You could also trim s's from the end of strings. you could use rtrim() for this. this might be a bad idea though, as taking of random characters from the end of strings could have unwanted results. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969513 Share on other sites More sharing options...
justAnoob Posted December 2, 2009 Author Share Posted December 2, 2009 kinda like keywords then. so then I would just search the keyword column of the database. I was hoping not to go that route but I guess it would be the easiest. Thanks for all your help guys. Quote Link to comment https://forums.phpfreaks.com/topic/183664-what-would-this-be-called/#findComment-969518 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.