dlsweb Posted November 27, 2014 Share Posted November 27, 2014 HiThis non php person would sure appreciate some help.My site has a simple search box.Upon searching for a keyword, it returns listings which match 1 of 10 keywords included in that specific listing- skey.$query .= " and keywords like '%$skey%' and category like '%Mycategory%'";I would like to also have the "bname" field checked for the specific keyword and included in the listings returned.Not knowing php at all, I tried this$query .= " and keywords like '%$skey%' or '%bname%' and category like '%Mycategory%'"; and$query .= " and keywords like '%$skey%' or '%$bname%' and category like '%Mycategory%'";which did not work.A little help with correct code would be great.Tks, Larry Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/ Share on other sites More sharing options...
ginerjm Posted November 27, 2014 Share Posted November 27, 2014 It may sound right when you say it in English but in code one must repeat each condition completely and NOT make the assumption that you do when you speak it. and (keywords like '%$skey%' or keywords like '%$bname%') and category like '%Mycategory%'"; (Note the set of parens too) PS - this is not PHP btw - it is sql Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/#findComment-1497832 Share on other sites More sharing options...
dlsweb Posted November 27, 2014 Author Share Posted November 27, 2014 thanks much but did not return bname listings and when I tried $query .= " and keywords like '%$bname%' and category like '%Mycategory%'"; rather than $query .= " and keywords like '%$skey%' and category like '%Mycategory%'"; it did not work either I guess I will have to hire someone to do tks Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/#findComment-1497839 Share on other sites More sharing options...
NotionCommotion Posted November 27, 2014 Share Posted November 27, 2014 I guess I will have to hire someone to do Definitely an option and maybe your best, but if so, you might need to give someone access to your server which is never great. Before doing so, you might wish to try some quick checks. Do what ginerjm recommended, and then echo the query before PHP tries to execute it and post the query. Or better yet, if you have access to your database, directly insert the query and see your response. Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/#findComment-1497842 Share on other sites More sharing options...
mikosiko Posted November 27, 2014 Share Posted November 27, 2014 What exactly is "bname"... A field in your table or a variable coming from another place? Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/#findComment-1497844 Share on other sites More sharing options...
dlsweb Posted November 27, 2014 Author Share Posted November 27, 2014 it is a field name Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/#findComment-1497845 Share on other sites More sharing options...
Barand Posted November 27, 2014 Share Posted November 27, 2014 in which case ... and (keywords like '%$skey%' or bname like '%skey%') and category like '%Mycategory%'"; Quote Link to comment https://forums.phpfreaks.com/topic/292749-non-php-person-needs-help/#findComment-1497846 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.