Hello,
I'm having a little problem displaying today's birthday, but it's basically cuase i'm trying to display today's birthday of mother or father from the same table.
Here's my table structure:
TABLE parents (
parent_id int(11) NOT NULL default '0',
mother_first_name varchar(70) NOT NULL default '',
mother_last_name varchar(70) NOT NULL default '',
mother_dob date NOT NULL default '0000-00-00',
mother_address varchar(100) NOT NULL default '',
mother_homephone varchar(24) NOT NULL default '',
mother_cellphone varchar(24) NOT NULL default '',
mother_occupation varchar(50) NOT NULL default '',
mother_workplace varchar(50) NOT NULL default '',
mother_workphone varchar(24) NOT NULL default '',
mother_compensation varchar(30) NOT NULL default '',
father_first_name varchar(70) NOT NULL default '',
father_last_name varchar(70) NOT NULL default '',
father_dob date NOT NULL default '0000-00-00',
father_address varchar(100) NOT NULL default '',
father_homephone varchar(24) NOT NULL default '',
father_cellphone varchar(24) NOT NULL default '',
father_occupation varchar(50) NOT NULL default '',
father_workplace varchar(50) NOT NULL default '',
father_workphone varchar(24) NOT NULL default '',
father_compensation varchar(30) NOT NULL default '',
PRIMARY KEY (parent_id)
)
Here's the birthday function:
function birthday ($birthday)
{
list($month,$day,$year) = explode("/",$birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
return $year_diff;
}
Now here is my problem with displaying.... I can only get the mother birthday name and lastname to show up, how do I get it to display the father b-day correct.
echo "<p><span class=\"headertext\">Today's Parent Birthday</span></p>";
echo "<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\" bgcolor=\"#ffffff\">";
$tday= date(d);
$tmonth= date(m);
$sql_parents_bday = "SELECT * FROM parents where (MONTH(mother_dob) = '$tmonth' AND DAYOFMONTH(mother_dob) = '$tday') OR (MONTH(father_dob) = '$tmonth' AND DAYOFMONTH(father_dob) = '$tday') order by parent_id DESC limit 5";
$result_parents_bday = mysql_query($sql_parents_bday);
if(mysql_num_rows($result_parents_bday) > '0')
{
while ($row_parent_bday=mysql_fetch_array($result_parents_bday)){
$parent_id=$row_parent_bday["parent_id"];
$mother_first_name=stripslashes($row_parent_bday["mother_first_name"]);
$mother_last_name=stripslashes($row_parent_bday["mother_last_name"]);
$father_first_name=stripslashes($row_parent_bday["father_first_name"]);
$father_last_name=stripslashes($row_parent_bday["father_last_name"]);
$mf_timestamp_dob=$row_parent_bday["mother_dob"];
$mf_changedate_dob="$mf_timestamp_dob";
list($mf_year_dob,$mf_month_dob,$mf_day_dob) = split('[-./]', $mf_changedate_dob);
$mother_dob=$mf_month_dob."/".$mf_day_dob."/".$mf_year_dob;
echo "<tr>";
echo "<td align='left'><span class='links_2'><a href='?id=students&&p=student_parents&&nid=$parent_id'>$mother_last_name, $mother_first_name</a></span> (";
echo birthday("$mother_dob");
echo " years) </td>";
echo "</tr>";
}
}
else {
echo "<tr>";
echo "<td>No parents have a birthday today</td>";
echo "</tr>";
}
echo "</table>";