Enjoy an ad free experience by logging in. Not a member yet?
Register .
10-06-2012, 09:55 PM
PM User |
#1
Regular Coder
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Birthdays in Current Month vb 4.2
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
Code:
<?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";
}
?>
Last edited by Feckie; 10-07-2012 at 11:47 PM ..
10-07-2012, 03:01 AM
PM User |
#2
Senior Coder
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
Shouldn't the section containing
Code:
$userid = $user ['userid'];
Be
Code:
$userid = $row ['userid'];
10-07-2012, 07:32 AM
PM User |
#3
Regular Coder
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
sunfighter
Shouldn't the section containing
Code:
$userid = $user ['userid'];
Be
Code:
$userid = $row ['userid'];
Tried that, it made no difference
10-07-2012, 02:33 PM
PM User |
#4
Senior Coder
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
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.
Last edited by sunfighter; 10-07-2012 at 02:36 PM ..
10-07-2012, 02:43 PM
PM User |
#5
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
What is the datatype of the birthday field? Is it a datetime (or any derivative of date and time)?
PHP Code:
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.
10-07-2012, 07:22 PM
PM User |
#6
Regular Coder
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
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
Code:
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();
}
10-07-2012, 09:05 PM
PM User |
#7
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
PHP Code:
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.
10-07-2012, 11:47 PM
PM User |
#8
Regular Coder
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Cheers Mate that works perfect
Quote:
Originally Posted by
Fou-Lu
PHP Code:
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.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 03:47 AM .
Advertisement
Log in to turn off these ads.