Sort Options

Share your CuteNews.RU skins and code snippets.

Sort Options

Postby scottdallas » Thu Jul 20, 2006 6:30 pm

I don't know about anyone else but even if this is posted only for my resource later, that's fine. I'm sure Google will pick this up. I'm always forgetting which to use... ASC or DESC for my sort options and I usually end up using 6 different ways.. so I wrote them all down for safe keeping so I could use over and over and never forget. Here it is:



Newest to Oldest

$sort = array('date', 'DESC');



Oldest to Newest

$sort = array('date', 'ASC');



Most Views to Least Views

$sort = array('views', 'DESC');



Least Views to Most Views

$sort = array('views', 'ASC');



Most Comments to Least Comments

$sort = array('comments', 'DESC');



Least Comments to Most Comments

$sort = array('comments', 'ASC');



If anyone thinks that this is a waste of a post, my feelings wont be hurt if you delete it.
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby scottdallas » Sun Oct 28, 2007 3:26 am

Updated list:

Newest to Oldest
$sort = array('date', 'DESC');

Oldest to Newest
$sort = array('date', 'ASC');

Most Views to Least Views
$sort = array('views', 'DESC');

Least Views to Most Views
$sort = array('views', 'ASC');

Most Comments to Least Comments
$sort = array('comments', 'DESC');

Least Comments to Most Comments
$sort = array('comments', 'ASC');

Alphabetical (A-Z)
$sort = array('title', 'ASC');

Alphabetical (Z-A)
$sort = array('title', 'DESC');

Sort By Date (Today)
$year = date('Y');
$month = date('n');
$day = date('d');

Most Viewed Posts (30 Days)
$mktime = (time() - 3600 * 24 * 30);
$year = date('Y', $mktime);
$month = date('m', $mktime);
$sort = array('views', 'DESC');

Sorting By Date & Time:
$year = date('Y');
$month = date('n');
$day = date('d') - 1;
$sort = array('comments', 'DESC');

Sort by author name:
$author = "username";
Everyday I'm tumblin http://scodal.tumblr.com
User avatar
scottdallas
 
Posts: 2209
Joined: Thu May 04, 2006 6:46 pm
Location: US

Postby Partyism » Wed Feb 25, 2009 4:20 pm

sorry for kicking this old topic but DESC or ASC is not working for me

Code: Select all
<?PHP
                  $schedule = true;
                  $sort = array('date', 'ASC');
                  $static['template'] = 'Evenementen';
                  $static['number'] = '3';
                  $static['category'] = '20';                  
                  i
Partyism
 
Posts: 399
Joined: Tue Sep 25, 2007 6:24 pm

Postby Torstein » Wed Feb 25, 2009 7:54 pm

you need to use
Code: Select all
$static['sort'] = array('date', 'ASC');

since the rest are static variables.
Torstein
 
Posts: 292
Joined: Thu Aug 03, 2006 11:19 pm

Postby Partyism » Wed Feb 25, 2009 9:03 pm

i know.. stupid me... :oops: hmmprff

thnx for your help!
Partyism
 
Posts: 399
Joined: Tue Sep 25, 2007 6:24 pm

Postby nam » Thu Feb 26, 2009 1:15 am

scottdallas wrote:Updated list:
Most Viewed Posts (30 Days)
$mktime = (time() - 3600 * 24 * 30);
$year = date('Y', $mktime);
$month = date('m', $mktime);
$sort = array('views', 'DESC');



This does not work for me, trying since long but it still shows overall articles sorted by view count regardless of its date.

On database level, the following SQL query on the table gives me the exact output I need:

Code: Select all
SELECT `title`
FROM `ru_news`
WHERE DATE_SUB( CURDATE( ) , INTERVAL 30
DAY ) <= FROM_UNIXTIME( date )
ORDER BY `views` DESC
LIMIT 0 , 10;
User avatar
nam
 
Posts: 221
Joined: Sat Dec 23, 2006 9:10 pm

Postby nam » Thu Feb 26, 2009 2:27 am

I found the problem.

Actually $time was set as false ($time = false;) in my show_news.php file. When removed that line, now it works fine.
User avatar
nam
 
Posts: 221
Joined: Sat Dec 23, 2006 9:10 pm

Postby Ramon » Wed Dec 23, 2009 11:44 pm

If you want to sort on multiple fields..

Code: Select all
$sort = array('category', 'ASC', ',', 'title', 'ASC');


with this you can achieve a result like this -> http://fminside.nl/teams/fm2010/

It first sorts on the column "comp" and then on "naam"..
Image
Ramon
 
Posts: 599
Joined: Wed Oct 12, 2005 8:51 pm
Location: Hoogeveen, NL

Postby typeman » Tue Jan 05, 2010 11:01 pm

scottdallas wrote:Updated list:
Most Viewed Posts (30 Days)
$mktime = (time() - 3600 * 24 * 30);
$year = date('Y', $mktime);
$month = date('m', $mktime);
$sort = array('views', 'DESC');


Guess what... it's not working for me either. I checked my "show_news.php" file to see if $time = false, but i couldn't even find that file... :( Can someone please help me? :D

Thanks XD
typeman
 
Posts: 102
Joined: Sat Oct 17, 2009 7:38 am

Postby typeman » Fri Jan 08, 2010 2:06 pm

Can anyone help? :) Thanks for your help! :)
typeman
 
Posts: 102
Joined: Sat Oct 17, 2009 7:38 am

Postby kini » Mon Jun 21, 2010 4:22 pm

sorry for the offtopic ...
do you know how i can sort by title???
thanks
kini
 
Posts: 3
Joined: Mon Jun 21, 2010 9:41 am

Postby eberswine » Mon Jun 21, 2010 10:23 pm

Code: Select all
Alphabetical (A-Z)
$sort = array('title', 'ASC');

Alphabetical (Z-A)
$sort = array('title', 'DESC');
User avatar
eberswine
 
Posts: 281
Joined: Thu Apr 26, 2007 7:23 pm

Postby kini » Tue Jun 22, 2010 7:57 am

thanks so much for your answer!!
but it not runs... :roll: i don't know why

needs some *.mdu modification??
i'm using the cutenews standar not the cutenews ru

<?PHP
$category = "1";
$sort = array('title', 'ASC');
include("cutenews/show_news.php");
?>


thanks!
kini
 
Posts: 3
Joined: Mon Jun 21, 2010 9:41 am

Postby kini » Tue Jun 22, 2010 8:31 am

ok! finally i find the answer here
http://cutephp.com/forum/index.php?showtopic=3733
thanks for your support!!!!
kini
 
Posts: 3
Joined: Mon Jun 21, 2010 9:41 am


Return to Skins and snippets



Who is online

Users browsing this forum: No registered users and 0 guests

cron