TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-22-2009, 05:15 PM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default 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>";
}
__________________
--
Regards
Shankar

Last edited by Wildhoney : 04-22-2009 at 11:28 PM.
shankar is offline  
Reply With Quote
Old 04-22-2009, 11:25 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
shankar (04-23-2009)
Old 04-23-2009, 03:12 AM   #3 (permalink)
The Wanderer
 
Join Date: Apr 2009
Posts: 19
Thanks: 9
shankar is on a distinguished road
Default Thanks

Thank you v much thank u vv much,, it worked
__________________
--
Regards
Shankar
shankar is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create a gallery class Tanax Advanced PHP Programming 25 02-19-2013 04:25 AM
Help on PHP MYSQL Forms Input deesudesu Absolute Beginners 1 03-20-2009 10:50 AM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM
Safe MySQL Parse Function Wildhoney Script Giveaway 2 11-30-2007 11:34 PM


All times are GMT. The time now is 07:16 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design