Welcome to WebmasterWorld Guest from 54.234.38.8

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

How to display To todays birthdays

please some one help me

     
3:59 pm on Jan 31, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 28, 2005
posts:79
votes: 0


Hi,
I have DOB in my user registeration.I want to know how to display today date birthdays usernames on my homepage please suggest me how to write code for it.Iam new bie to php.
5:38 pm on Jan 31, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 2, 2003
posts:129
votes: 0


Get the date using php's Date function.
[uk.php.net...]

Then format the data to match the format used in your database and store as variable "$todaysdate"
Then simply query the database to display all users where DOB = $todaysdate.
Sorry if you wanted the actual code but its real easy if you already know how to query a database and display the results.

11:55 am on Feb 1, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 28, 2005
posts:79
votes: 0


i tried this

<?php require_once('Connections/connBlog.php');?>
<?php
$today= date("y-m-d");
echo $today;
?>
<?php
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_connBlog, $connBlog);
$query_Recordset1 = "SELECT firstName FROM tbl_users WHERE birthday='$today'";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $connBlog) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

<table border="0">
<tr>
<td>username</td>
<td>birthday</td>
</tr>
<?php do {?>
<tr>
<td><?php echo $row_Recordset1['firstName'];?></td>
<td><?php echo $row_Recordset1['birthday'];?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));?>
</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

and finally i laughed at me because no one will have birthday on today date.My db DOB format is YYYY-MM-DD.I think ishouldnt consider year .I should only consider month and date and we have to match with db's DOB.Please suggest me how can i do like this.

12:19 pm on Feb 1, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 15, 2004
posts:941
votes: 0


Hi phprockz!

I suggest you to store all dates as unixtime (integer, 11 or 12) while taking a look at the date() function on the php_manual to find out how to convert dates to unixtime as well as compare months and days only.

Hope the best.

1:58 pm on Feb 1, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 28, 2005
posts:79
votes: 0


MY date format is 2006-02-01.I think its unix format only .Please suggest how to get todays birthdays from database.if u have any logic plz mentiion here.
1:57 am on Feb 2, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15755
votes: 0


another option would be to store day, month and year in seperate columns and then select where day equals today and month equals this month.
2:26 pm on Feb 2, 2006 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


Or use some date/time functions [dev.mysql.com].

$query_Recordset1 = "SELECT firstName FROM tbl_users WHERE MONTH(birthday) = MONTH(NOW() AND DAY(birthday) = DAY(NOW());