View Full Version : Resolved Birthdays in Current Month vb 4.2
Feckie 10-06-2012, 09:55 PM I am trying to display the user birthdays this month in vbulletin 4.2
I have done the script below, although there is a birthday set this month
it shows " No Birthdays This Month "
Can anyone help please
<?php
include("connect.php");
$result = mysql_query("SELECT userid,username,birthday FROM user WHERE MONTH(birthday) = MONTH(NOW())");
if( mysql_num_rows( $result ) != 0 ) {
while ( $row = mysql_fetch_array($result))
{
$userid = $user['userid'];
$username = $user['username'];
$birthday = $user['birthday'];
$birthday = explode("-", $birthday);
$birthmonth = $birthday[0];
if ($birthmonth = $month)
{
echo "<a href='member.php?u=$userid'>$username</a>, ";
}
}
}
else{
echo "No Birthdays This Month";
}
?>
sunfighter 10-07-2012, 03:01 AM Shouldn't the section containing
$userid = $user['userid']; Be $userid = $row['userid'];
Feckie 10-07-2012, 07:32 AM Shouldn't the section containing
$userid = $user['userid']; Be $userid = $row['userid'];
Tried that, it made no difference
sunfighter 10-07-2012, 02:33 PM What did you try, please post, because there are at lest three of them. And to save time echo out what you get for $birthday, $birthmonth, and $month.
Fou-Lu 10-07-2012, 02:43 PM What is the datatype of the birthday field? Is it a datetime (or any derivative of date and time)?
if ($result = mysql_query("SELECT userid,username,birthday FROM user WHERE MONTH(birthday) = MONTH(NOW())"))
{
if (mysql_num_rows($result) > 0)
{
$i = 0;
while ($row = mysql_fetch_row($result))
{
list($userid, $username, $birthday) = $row;
if ($i++ > 0)
{
print ', ';
}
printf('<a href="member.php?u=%d">%s</a>', $userid, $username);
}
else
{
print 'No birthdays this month';
}
}
else
{
print 'Error in query: ' . mysql_error();
}
I would be surprised if a birthday isn't a date or date type datatype, but given that this is using old mysql code and not using mysqli or PDO, its hard to say what datatype has been chosen.
Feckie 10-07-2012, 07:22 PM Fou-Lu I got yours to work with a few adjustments, Thanks
ie: it was "birthday_search" not "birthday" My Bad :)
Next Question:
How would I add the actual date after each name ...
It now shows as follows
name
name
name
if ($result = mysql_query("SELECT userid,username,birthday_search FROM user WHERE MONTH(birthday_search) = MONTH(NOW())"))
{
if (mysql_num_rows($result) > 0)
{
$i = 0;
while ($row = mysql_fetch_row($result))
{
list($userid, $username, $birthday_search) = $row;
if ($i++ > 0)
{
print '<br /> ';
}
printf('<a href="member.php?u=%d">%s</a>', $userid, $username);
} }
else
{
print 'No birthdays this month';
}
}
else
{
print 'Error in query: ' . mysql_error();
}
Fou-Lu 10-07-2012, 09:05 PM printf('<a href="member.php?u=%d">%s</a> %s', $userid, $username, $birthday_search);
Looks like its a date datatype, so that should show without needing formatting.
Feckie 10-07-2012, 11:47 PM Cheers Mate that works perfect :thumbsup:
printf('<a href="member.php?u=%d">%s</a> %s', $userid, $username, $birthday_search);
Looks like its a date datatype, so that should show without needing formatting.
|
|