sam02 Posted April 21, 2008 Share Posted April 21, 2008 Hi, I have got a problem with my count function. I have two tables personal_details, sources. Personal Details -------------------- Title Name Address etc... source_id Source --------- source_id source I want to create a query that shows the total number of customers entered with a specific source for example my result should show: Source - Total -------------------------------- Source 1 - 2 Source 2 - 1 Source 3 - 5 "SELECT personal_details.*, source.source COUNT(source_id) FROM personal_details, source WHERE (personal_details.source_id=source.source_id) AND TO_DAYS(NOW()) - TO_DAYS(leaddate) <= 30 GROUP BY source_id" Anybody Help? Thanks Link to comment https://forums.phpfreaks.com/topic/102143-problem-with-count-function/ Share on other sites More sharing options...
micah1701 Posted April 21, 2008 Share Posted April 21, 2008 what if you alias your COUNT() result, like: SELECT personal_details.*, source.source COUNT(source_id) AS total_source_id FROM personal_details, source WHERE (personal_details.source_id=source.source_id) AND TO_DAYS(NOW()) - TO_DAYS(leaddate) <= 30 GROUP BY source_id" Link to comment https://forums.phpfreaks.com/topic/102143-problem-with-count-function/#findComment-522866 Share on other sites More sharing options...
sam02 Posted April 22, 2008 Author Share Posted April 22, 2008 I just get an error with adding that bit of code Link to comment https://forums.phpfreaks.com/topic/102143-problem-with-count-function/#findComment-523773 Share on other sites More sharing options...
Barand Posted April 22, 2008 Share Posted April 22, 2008 try <?php $sql = "SELECT s.source, COUNT(p.source_id) as total FROM source s LEFT JOIN personal_details p ON (p.source_id=s.source_id) AND TO_DAYS(NOW()) - TO_DAYS(p.leaddate) <= 30 GROUP BY s.source_id"; ?> Link to comment https://forums.phpfreaks.com/topic/102143-problem-with-count-function/#findComment-523794 Share on other sites More sharing options...
sam02 Posted April 28, 2008 Author Share Posted April 28, 2008 Hi, sorry for not replying sooner, but i still cant get that code to work, im not sure what is going wrong, there isnt an error but no data is shown on the page any help is greatly appreciated Thanks Link to comment https://forums.phpfreaks.com/topic/102143-problem-with-count-function/#findComment-528758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.