ngreenwood6 Posted December 10, 2008 Share Posted December 10, 2008 I have the following code: $query = "SELECT * FROM work WHERE LIKE '%$search%'"; It is not working. I want it to select anything in the table that matches the search. Can someone please help me. thanks in advance Quote Link to comment Share on other sites More sharing options...
gevans Posted December 10, 2008 Share Posted December 10, 2008 you need to choose one field to check against Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 Read this please. http://www.freewebmasterhelp.com/tutorials/phpmysql/8 $search from the form ok.... $query = "SELECT * FROM work WHERE field_name LIKE '%$search%'"; Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 10, 2008 Author Share Posted December 10, 2008 Is there a way that I can choose more than one field like: $query = "SELECT * FROM work WHERE requests, solutions LIKE '%$search%'"; Quote Link to comment Share on other sites More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 $query = "SELECT * FROM work WHERE requests LIKE '%$search%' OR solutions LIKE '%$search%'"; Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 10, 2008 Author Share Posted December 10, 2008 Thanks brian but I have two more questions. With that query will it select the results from requests and solutions for anything that matches $search or will it do only one or the other. the other question is can you perform more than 2 or is it limited to 2. Quote Link to comment Share on other sites More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 if the row it looks at has $search in either field a or b (or more fields, no limit) it will return that row and then move on checking the next one and so on and so on till it reaches the end of the table. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 Would this work? <?php $query = "SELECT membera.usera, memberb.userb FROM membera,memberb WHERE membera.usera LIKE '%$search%' OR memberb.userb LIKE '%$search%'"; ?> Quote Link to comment Share on other sites More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 you have two tables with users on it? Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 yep, Can i now use the both tables, to search the two fields example find user "john" Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted December 10, 2008 Author Share Posted December 10, 2008 Thanks for the help. That solved my issue. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 Dont go mate i am asking a good question here... for us both to no. Quote Link to comment Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 yep, Can i now use the both tables, to search the two fields example find user "john" Yes you can. Quote Link to comment Share on other sites More sharing options...
Brian W Posted December 10, 2008 Share Posted December 10, 2008 premiso is more experience than I am, so I'll just agree with him cuz i don't see why it wouldn't Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 Thank you i new that... Testing now what faster A or B A <?php $query = "SELECT membera.usera, memberb.userb FROM membera,memberb WHERE membera.usera LIKE '%$search%' OR memberb.userb LIKE '%$search%'"; ?> B <?php $query = "SELECT membera.usera, memberb.userb FROM membera as A,memberb as B WHERE A.usera LIKE '%$search%' OR B.userb LIKE '%$search%'"; ?> Quote Link to comment Share on other sites More sharing options...
bluesoul Posted December 10, 2008 Share Posted December 10, 2008 http://www.google.com/search?q=query+analyzer Hard to know without seeing your database so download an analyzer and see what works best for you. Quote Link to comment Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 The second will error, you do not need to use as keyword (cannot use as keyword in table definitions. <?php $query = "SELECT membera.usera, memberb.userb FROM membera A,memberb B WHERE A.usera LIKE '%$search%' OR B.userb LIKE '%$search%'"; ?> Either will be just as fast, but I prefer the method above, less chance of an error for mis-writing the whole table name. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 10, 2008 Share Posted December 10, 2008 why wont this work it will i guessing... <?php $query = "SELECT membera.usera, memberb.userb FROM membera as A AND memberb as B WHERE A.usera LIKE '%$search%' OR B.userb LIKE '%$search%'"; ?> Quote Link to comment Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 <?php $query = "SELECT membera.usera, memberb.userb FROM membera as A AND memberb as B WHERE A.usera LIKE '%$search%' OR B.userb LIKE '%$search%'"; ?> Invalid SQL, as cannot be in the FROM part, you also are using AND, which would throw an error, and you do not have a comma. corrected <?php $query = "SELECT A.usera, B.userb FROM membera A, memberb B WHERE A.usera LIKE '%$search%' OR B.userb LIKE '%$search%'"; ?> If you would like further guidance, I would suggest creating a new topic =) Quote Link to comment 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.