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 Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/ 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 Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711689 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%'"; Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711690 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%'"; Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711724 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%'"; Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711730 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711735 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711751 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%'"; ?> Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711776 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? Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711778 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" Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711782 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711783 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711786 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711787 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 Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711792 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%'"; ?> Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711794 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711797 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. Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711798 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%'"; ?> Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711805 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 =) Link to comment https://forums.phpfreaks.com/topic/136395-solved-help-with-a-query/#findComment-711809 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.