pault Posted November 23, 2010 Share Posted November 23, 2010 (PHP version 5.2.14) My situation is that I have table of Users and a table of Adverts which are created by those Users. I want to search the Adverts, selecting for for dates, price, etc, which is all very straightforward. The difficulty comes in that the Users are sometimes enabled and sometimes disabled, and when they are disabled, none of their adverts should appear. What I need then is something like "select * from Adverts where (adverts.dates=etc, etc) AND where User.enabled=true" I've been looking at joins and subqueries but the examples don't seem to match what I am looking for. Grateful for any help. Quote Link to comment https://forums.phpfreaks.com/topic/219597-is-it-possible-to-search-one-table-while-using-another-as-a-condition/ Share on other sites More sharing options...
mikosiko Posted November 23, 2010 Share Posted November 23, 2010 most likely possible... I want to search the Adverts, selecting for for dates, price, etc, which is all very straightforward post the code that you are using for that.... and additional your table's definitions a simple join should solve your issue if your table design is correct. Quote Link to comment https://forums.phpfreaks.com/topic/219597-is-it-possible-to-search-one-table-while-using-another-as-a-condition/#findComment-1138575 Share on other sites More sharing options...
jim_keller Posted November 24, 2010 Share Posted November 24, 2010 this should do it: SELECT * FROM Adverts, Users WHERE (adverts.dates=etc, etc) AND Users.enabled=1 Quote Link to comment https://forums.phpfreaks.com/topic/219597-is-it-possible-to-search-one-table-while-using-another-as-a-condition/#findComment-1139133 Share on other sites More sharing options...
pault Posted November 24, 2010 Author Share Posted November 24, 2010 this should do it: SELECT * FROM Adverts, Users WHERE (adverts.dates=etc, etc) AND Users.enabled=1 Thanks. I shall try that. Quote Link to comment https://forums.phpfreaks.com/topic/219597-is-it-possible-to-search-one-table-while-using-another-as-a-condition/#findComment-1139219 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.