Location: PHPKode > scripts > Birthday Ordering > birthday-ordering/ClsFriendBirthdays.cls.php
<?
	/*
		Developed By: 	Md. Aminul Islam.
						Email: hide@address.com
		
		This class is very usefull for you to find out all members name and upcoming birthdays.
		Be carefull about the version of your MySql you are using. If you use MySql version 3.0 then 
		Please uncomment line 29 and comment line 31.
		Any advice or correction for this class will be highly appreciated.
	*/
	class ClsFriendBrithdays
	{
		var $Host="localhost";
		var $UserName="root";
		var $Password="";
		var $DbName="aminul";
		
		var $BirthDay;	//$BirthDay="Apr 9th"
		var $FullName;
		var $MyId;

		var $PositiveMemdIds=array();		//First time hold Positive Values And Finally Final values.
		var $PositiveOrderSerial=array();
		var $NegativeMemdIds=array();
		var $NegativeOrderSerial=array();
		var $TotalRecord=0;	// Total Number of Record.
		
		// If your MySql version is 3.0 or greater And less then 5.0
		//var $Query="SELECT MemberId, DateOfBirth, SUBSTRING(DateOfBirth,6,2)-$MonthNo MonthOrder, SUBSTRING(DateOfBirth,8,2) DayOrder FROM registration ORDER BY MonthOrder,DayOrder";
		// If your MySql version is 5.0 or greater.
		var $Query;
		
		function ClsFriendBrithdays()	//Constructor. Make Connection.
		{
			if(!mysql_connect($this->Host,$this->UserName,$this->Password))
				echo "Error in connection.";
			if(!mysql_select_db($this->DbName))
				echo "Error in database selection.";
			//$MonthNo=date("m");
			$MonthNo=10;
			$this->Query="SELECT MemberId, DateOfBirth, MONTH(DateOfBirth)-$MonthNo MonthOrder, DAY(DateOfBirth) DayOrder FROM registration ORDER BY MonthOrder,DayOrder";
		}
		function ComingBirthdayFriendsId()
		{
			$MonthNo=date("m");
			$TodayDay=date("d");		//$MonthNo=3;	$TodayDay=22;	
			$MemberId=$this->MyId;		//echo "Current Month: ".$MonthNo." Day: ".$TodayDay."<br>";

			$Sql=$this->Query;
			//echo "SQL :".$Sql;
			$QBirthDays=mysql_query($Sql);
			if(mysql_num_rows($QBirthDays))
			while($RsBirth=mysql_fetch_object($QBirthDays))
			{
				if($RsBirth->MonthOrder>0)	//Positive Values [Greater then current month.]
				{
					$this->PositiveMemdIds[]=$RsBirth->MemberId;
					$this->PositiveOrderSerial[]=$RsBirth->MonthOrder;
				}
				elseif($RsBirth->MonthOrder==0)	//[Current month.]
				{
					//echo "<br><br>".$RsBirth->DayOrder." Today:".$TodayDay."<br><br>";
					if($RsBirth->DayOrder>0)
					{
						$this->PositiveMemdIds[]=$RsBirth->MemberId;
						$this->PositiveOrderSerial[]=$RsBirth->MonthOrder;
					}
					else
					{
						$this->NegativeMemdIds[]=$RsBirth->MemberId;
						$this->NegativeOrderSerial[]=$RsBirth->MonthOrder;
					}
				}
				else	//Negative Values [ Less then current month]
				{
					$this->NegativeMemdIds[]=$RsBirth->MemberId;
					$this->NegativeOrderSerial[]=$RsBirth->MonthOrder;
				}
			}
			/*echo "<br>Before Processing:<br>";
			$this->DisplayMemInfo();
			echo "<br>After Processing:<br>";*/
			$this->ArrangeOrdering();
			//$this->ArrayValues();	//Display Array Values
			//$this->DisplayMemInfo();
		}
		function DisplayMemInfo()
		{
			for($I=0;$I<count($this->PositiveMemdIds);$I++)
			{
				$this->OneFriendsDetail($this->PositiveMemdIds[$I]);
				echo "<br>Name: <strong>".$this->FullName."</strong> Birth day: <strong>".$this->BirthDay."</strong><br>";
			}
		}
		
		function ArrangeOrdering()	//Positive Array = Positive Array + Negative Value [First Positive then Negative]
		{
			//$this->NegativeMemdIds=array_reverse($this->NegativeMemdIds);
			//$this->NegativeOrderSerial=array_reverse($this->NegativeOrderSerial);
			
			$this->PositiveMemdIds=array_merge($this->PositiveMemdIds,$this->NegativeMemdIds);
			$this->PositiveOrderSerial=array_merge($this->PositiveOrderSerial,$this->NegativeOrderSerial);
			//echo "total".count($this->PositiveMemdIds);
			$this->TotalRecord=count($this->PositiveMemdIds);
		}
		
		function OneFriendsDetail($MemberId)
		{
			$AminQuery="SELECT FirstName,SirName,DateOfBirth FROM registration WHERE MemberId=$MemberId";
			$QMemInfo=mysql_query($AminQuery);
			if(mysql_num_rows($QMemInfo)>0)
			{
				$RsMemInfo=mysql_fetch_object($QMemInfo);
				$this->FullName=$RsMemInfo->FirstName." ".$RsMemInfo->SirName;
				$this->BirthDay=$this->BirthDayFormating($RsMemInfo->DateOfBirth);
			}
		}
		
		function BirthDayFormating($DateOfBirth)	//Input $DateOfBirth="1980-09-10" Outpu: Sep 10th
		{
			$tok=strtok("$DateOfBirth","-");
				$Year=$tok;
			$tok = strtok ("-");
				$Month=$tok;						
			$tok = strtok ("-");
				$Day=$tok;
			$FormatedBirthDay=date("M jS", mktime(0, 0, 0, $Month, $Day));	//Outpur- Sep 10th
			return $FormatedBirthDay;
		}

		function ArrayValues()	// Display Both Positive and Negative Array.
		{
			for($I=0;$I<count($this->PositiveMemdIds);$I++)
				echo "<br>Positive Id: ".$this->PositiveMemdIds[$I]." Order: ".$this->PositiveOrderSerial[$I];
			echo "<br><br>";
			for($I=0;$I<count($this->NegativeMemdIds);$I++)
				echo "<br>Negative Id: ".$this->NegativeMemdIds[$I]." Order: ".$this->NegativeOrderSerial[$I];
		}
	}
?>
Return current item: Birthday Ordering