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 01-10-2012, 06:30 PM   #1 (permalink)
Shonir IT Solutions
 
shonir's Avatar
 
Join Date: Jul 2011
Location: Sialkot, Pakistan
Posts: 10
Thanks: 0
shonir is on a distinguished road
Unhappy Storing PHP time() in mySQL and getting problem to sorting recods

im working on a project repoting.database have almost up to 50000 records in a table. in this project i need to sort out records by days or month or by year. but problem is every recods have a column "addtime" there time() has been stored when record enterd.

i checked and with date("d/m/Y",$records['addtime']) working fine. but how i can show by day or year and month below is my code please help its very importent and urgent.

$result = $sm->queryfnc("select * from {tbl}authors where status=1 and YEAR(addtime)=2011", 'Get Result');
$rows = $sm->rowsfnc($result, 'Get Rows');
if($rows>0){
while($records = $sm->recordsfnc($result, 'Get Records')){
echo date("d/m/Y", $records['addtime']).' <br>';

}
}

Thanks in advance for your attention
__________________
Reputation is for time; character is for eternity.
Send a message via MSN to shonir Send a message via Yahoo to shonir Send a message via Skype™ to shonir
shonir is offline  
Reply With Quote
Old 01-17-2012, 06:01 PM   #2 (permalink)
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

You can use sql time functions to do this something like:

SQL Code:
SELECT *, DAYOFMONTH(`addtime`) AS monthday, MONTHNAME(`addtime`) AS montho, YEAR(`addtime`) AS yearo
FROM `sorting-ts-dates`
WHERE YEAR(`addtime`) LIKE 2012
ORDER BY montho ASC
I am not sure what do you refer by sorting of day, because there is days of the month, days of the year, and days of the week. But you can do it from mysql without doing too much work in PHP. Just choose the documentation of the right version of MySQL that you are using, even though they don't differ much from version to version, but just to be safe.
tony is offline  
Reply With Quote
Old 02-18-2012, 08:47 PM   #3 (permalink)
The Wanderer
 
AxelG's Avatar
 
Join Date: Feb 2012
Posts: 16
Thanks: 0
AxelG is on a distinguished road
Default

I had something similar to do. I have used a php class to do calculations on time :
http://www.phpclasses.org/package/46...m-formats.html
AxelG 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


All times are GMT. The time now is 06:42 PM.

 
     

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