Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2009
    Posts
    208
    Thanks
    31
    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>,&nbsp;";
        }
    
    }
    }
    else{
            echo "No Birthdays This Month";
        }
    ?>
    Last edited by Feckie; 10-08-2012 at 12:47 AM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,719
    Thanks
    25
    Thanked 662 Times in 661 Posts
    Shouldn't the section containing
    Code:
    $userid = $user['userid'];
    Be
    Code:
    $userid = $row['userid'];

  • #3
    Regular Coder
    Join Date
    Jan 2009
    Posts
    208
    Thanks
    31
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    Shouldn't the section containing
    Code:
    $userid = $user['userid'];
    Be
    Code:
    $userid = $row['userid'];
    Tried that, it made no difference

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,719
    Thanks
    25
    Thanked 662 Times in 661 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 03:36 PM.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 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.

  • #6
    Regular Coder
    Join Date
    Jan 2009
    Posts
    208
    Thanks
    31
    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();
    }

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 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.

  • #8
    Regular Coder
    Join Date
    Jan 2009
    Posts
    208
    Thanks
    31
    Thanked 0 Times in 0 Posts
    Cheers Mate that works perfect


    Quote Originally Posted by Fou-Lu View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •