TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   php mysql month function?!! (http://www.talkphp.com/general/4176-php-mysql-month-function.html)

shankar 04-22-2009 05:15 PM

php mysql month function?!!
 
I want to create php code to only display user to view only entries from a particular month, can anybody help me!!
this is the code i used; its not working .. can any1 fix it up.

php Code:
$get_month = '01'
$query = "SELECT * FROM stud_attendance WHERE username='$username',month(date)='$get_month'";
$result = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($result) == 0)
{
   header("Location:stud_no_attend.php");
}
else
{

    echo "<table border=1px cellpadding=3 width=430px>";
    while ($row = mysql_fetch_assoc($result))
    {
        echo "<tr>";
        echo "<td>" . $row['date'] . "</td>";
        echo "<td>" . $row['status'] . "&nbsp;&nbsp;</td>";
        echo "<td>" . $row['reason'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
}

Wildhoney 04-22-2009 11:25 PM

It would appear as though the MONTH() function returns it without the preceding zero and so it would be like the following:

sql Code:
SELECT * FROM users WHERE username = 'Wildhoney' AND MONTH(date) = 3

Try setting your $get_month variable to (int) 3.

Edit: I've also noticed you've not used the AND keyword between the username and date clauses, instead you've used a comma. This will simply cause MySQL to throw an error.

shankar 04-23-2009 03:12 AM

Thanks
 
Thank you v much thank u vv much,, it worked


All times are GMT. The time now is 01:02 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0