brown2005 Posted November 3, 2006 Share Posted November 3, 2006 i have two tables[b]currency[/b]currency_idcurrency_currency[b]adverts[/b]adverts_idadverts_currencyi want to print all currency's (that have 1 or more in adverts) from currency and then how many adverts have this currency in adverts... Link to comment https://forums.phpfreaks.com/topic/26067-solved-echo-list-of-currencies-plus-the-number-of-these-from-a-table/ Share on other sites More sharing options...
craygo Posted November 3, 2006 Share Posted November 3, 2006 you will have to make it relational in order to reference one to the other.add a field in the adverts table to reference the currency tableadvertsadverts_idcurr_idadverts_currencynow you can query one based on the other[code]$sql = "SELECT * FROM currency LEFT JOIN adverts ON currency_id = curr_id";[/code]Ray Link to comment https://forums.phpfreaks.com/topic/26067-solved-echo-list-of-currencies-plus-the-number-of-these-from-a-table/#findComment-119175 Share on other sites More sharing options...
Barand Posted November 3, 2006 Share Posted November 3, 2006 SELECT c.currency_currency, COUNT(a.advert_id)FROM currency cINNER JOIN adverts a ON c.currency_id = a.advert_currencyGROUP BY c.currency_currency Link to comment https://forums.phpfreaks.com/topic/26067-solved-echo-list-of-currencies-plus-the-number-of-these-from-a-table/#findComment-119192 Share on other sites More sharing options...
brown2005 Posted November 4, 2006 Author Share Posted November 4, 2006 thanks barand, spot on. exactly wat i needed Link to comment https://forums.phpfreaks.com/topic/26067-solved-echo-list-of-currencies-plus-the-number-of-these-from-a-table/#findComment-119579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.