Birthdays problem

    Date: 09/24/05 (PHP Community)    Keywords: php, mysql, database, sql, web

    I'm doing a web application with PHP and MySQL where members can enter their birthday on their profile. I've done a nice monthly calendar view, and I want to populate the calendar with members' birthdays.

    Can anyone advise me the best way of doing this? Obviously I don't want to do a database request for each day: "Does anybody have a birthday on this day?" - I think we can all guess that 30 database requests would be rather excessive for one page!!

    What I'd like to do is one database request to get all the birthdays for the month and then write it to a 2-dimensional array. Each row in the array will have the user's name, their userid (to link to their profile) and the day of the month which is their birthday. Then all I need do is ask the array if there's any birthdays when I'm writing out the days.

    The trouble is, I'm very unfamiliar with arrays and I'm not sure the best way to do this. Can anyone help?


    Update
    I've found a very useful function which is helping a lot:

    $birthdayquery = "SELECT ID, RealName, DOBDay from Users where DOBMonth = '$month'";
    $birthdays = mysql_query($birthdayquery);
    $arrayindex = 0;
    while ( $birthdayarray[$arrayindex++] = mysql_fetch_assoc($birthdays) );

    You can then do

    $arrayindex = 0;
    foreach ($birthdayarray as $value) {
    	if ($birthdayarray[$arrayindex]["DOBDay"] == $day) {
    		echo $birthdayarray[$arrayindex]["RealName"];
    		echo "'s birthday";
    	}
    	$arrayindex++;
    }


    I think this is going to work!

    Source: http://www.livejournal.com/community/php/346726.html

« Get Rid of Those Pesky Symbols || Converting time to seconds »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home