Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 09:55 PM   PM User | #1
Feckie
Regular Coder

 
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Feckie has a little shameless behaviour in the past
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-07-2012 at 11:47 PM..
Feckie is offline   Reply With Quote
Old 10-07-2012, 03:01 AM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
Shouldn't the section containing
Code:
$userid = $user['userid'];
Be
Code:
$userid = $row['userid'];
sunfighter is offline   Reply With Quote
Old 10-07-2012, 07:32 AM   PM User | #3
Feckie
Regular Coder

 
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Feckie has a little shameless behaviour in the past
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
Feckie is offline   Reply With Quote
Old 10-07-2012, 02:33 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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..
sunfighter is offline   Reply With Quote
Old 10-07-2012, 02:43 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-07-2012, 07:22 PM   PM User | #6
Feckie
Regular Coder

 
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Feckie has a little shameless behaviour in the past
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();
}
Feckie is offline   Reply With Quote
Old 10-07-2012, 09:05 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 10-07-2012, 11:47 PM   PM User | #8
Feckie
Regular Coder

 
Join Date: Jan 2009
Posts: 196
Thanks: 29
Thanked 0 Times in 0 Posts
Feckie has a little shameless behaviour in the past
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.
Feckie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:47 AM.


Advertisement
Log in to turn off these ads.