Alright, another post. This one seems to be the most complex thing I have ever tried. So, I am making a site where a user can post jokes and vote on them. They can only vote up, so a digg like system. I want the users to be able to sort the list of jokes by vote within the last 24 hours. In other words, jokes posted within the last 24 hours , whichever has the most will be on top.
As of now, I am fetching jokes via a mysql query and a while array. It can sort jokes by category (by retrieving URL variable catid) right now, an I need it to also sort by Daily Top, and Weekly top. There can be potentially 2 variables in the url (like index.php?catid=3&sort=daily), so I need too know how I would sort the data. Would I sort the array or the query. I wanted to do it by query, but I don't know how to specify a time range in the query.
I have ideas on how I would implement it, just got to find out how to code it. I have been researching for about an hour and still am. The links below are what I have gathered through my research. I don't know if they are any help, but it's worth a shot.
http://www.php.net/manual/en/array.sorting.php
http://www.webmasterworld.com/forum88/9531.htm
http://www.tizag.com/mysqlTutorial/mysqlorderby.php
http://us2.php.net/manual/en/function.strtotime.php
http://ca3.php.net/manual/en/function.sort.php
epicrevolt
6
Junior Poster in Training
Recommended Answers
Jump to PostI'd use query rather than sort via array.
You could have a table like:
joke_id | today | previous
You could run a cronjob at midnight to transfer add today to previous and setting today to 0.THis just looks at last 24 hours and …
Jump to PostI'm no expert so all I can do is offer my opinion...
When working with php and mysql, I always try to fetch the optimal results first in mysql and if I can't do it with mysql then I'll format with PHP. IF you have a date/time field in …
Jump to Postcool, good luck on it. just post here if you run into any problems
All 9 Replies
diafol
qazplm114477
14
Junior Poster
epicrevolt
6
Junior Poster in Training
qazplm114477
14
Junior Poster
epicrevolt
6
Junior Poster in Training
qazplm114477
14
Junior Poster
epicrevolt
6
Junior Poster in Training
qazplm114477
14
Junior Poster
epicrevolt
6
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.