PHP to pull age/DOB data from vBulletin forum

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mfaulkner
Forum Newbie
Posts: 1
Joined: Tue Mar 08, 2011 3:42 pm

PHP to pull age/DOB data from vBulletin forum

Post by mfaulkner »

Hey,

I'm a moderator/admin on a vBulletin powered forum. First up, hands in the air, I'm really not a coder and have exceptionally limited php experience from many, many years ago.

Basically we're trying to pull together some statistics for our forum usage/demographics and one thing we want to look at is the age of users. As part of the sign up process users are promoted to enter their DOB, and it's this data we'd like to access.

I'm assuming (yup, dangerous thing to do I know!) that it would be possible to use some php code to pull this DOB data out of the SQL database? Not overly fussy whether the data comes out raw (ie. just a list of DOB's) or as a list of ages, as either way I can plug it into a spreadsheet to analyse and make into pretty graphs to present to the powers that be!


Can anybody please point me in the right direction?


Thanks,

Marc
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP to pull age/DOB data from vBulletin forum

Post by John Cartwright »

Assuming you know how to connect to your database, and you are using MySQL database, a quick solution would be to perform a query like

Code: Select all

$sql = "SELECT FLOOR((TO_DAYS(NOW())- TO_DAYS(`your_dob_column`)) / 365.25) AS `age` FROM `your_users_table`";

$fp = fopen('ages.txt', 'w');

while ($row = mysql_fetch_assoc($result)) {
   fputcsv($fp, $row);
}

fclose($fp);
Which will generate a csv file called ages.txt that you can easy load into excel.
Post Reply