CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Resolved Birthdays in Current Month vb 4.2 (http://www.codingforums.com/showthread.php?t=275524)

Feckie 10-06-2012 09:55 PM

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>,&nbsp;";
    }

}
}
else{
        echo "No Birthdays This Month";
    }
?>


sunfighter 10-07-2012 03:01 AM

Shouldn't the section containing
Code:

$userid = $user['userid'];
Be
Code:

$userid = $row['userid'];

Feckie 10-07-2012 07:32 AM

Quote:

Originally Posted by sunfighter (Post 1277129)
Shouldn't the section containing
Code:

$userid = $user['userid'];
Be
Code:

$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)?
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.

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


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();
}


Fou-Lu 10-07-2012 09:05 PM

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.

Feckie 10-07-2012 11:47 PM

Cheers Mate that works perfect :thumbsup:


Quote:

Originally Posted by Fou-Lu (Post 1277322)
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.



All times are GMT +1. The time now is 10:58 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.