Hi everyone,
I need a way to create a range of users age from a database. I need to display it in this format:
16 | 3% | 0-17 Years
80 | 15% | 18-24 Years
127 | 24% | 25-34 Years
53 | 10% | 35-49 Years
5 | 1% | 50+ Years
The first column is the amount of people, the second column is the percent and the third is the age range.
All I have is their born year in a column named 'year_born'. I have created this MySQL query to get the amount of users per born year:
select count(id) as total, year_born from jos_users where ((year_born > DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -90 YEAR), '%Y')) and (year_born < DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL -10 YEAR), '%Y'))) group by year_born order by total desc;
This returns me something like this:
total year_born
1368 1970
1288 1975
1263 1974
1240 1973
1219 1971
1183 1976
1182 1972
1176 1977
1165 1965
1160 1968
1115 1969
1112 1980
1091 1967
1058 1966
1051 1978
1023 1979
1022 1964
994 1962
947 1960
933 1963
862 1961
835 1981
806 1982
Now that I have that data, how can I create the report that I actually need to display? Can it be done using sub-selects or maybe using some MySQL functions or any suggestion on the PHP code needed to create the report using the available data?
Any help will be greatly appreciated...
Thanks!