/    Sign up×
Community /Pin to ProfileBookmark

Sorting a List

I’m running a third party php script and am having trouble setting the order for a list. The list (see the attached image) is divided into 2, “cat_featured” and “started” at present they are both set to the same order, with the most recent appearing at the top of the list.

What I am trying to do is sort it so that the cat_featured items are sorted randomly and the “started” items are left the same (sorted by most recent first). Here is all the necessary code I think:

[code=php]function SetOrder($SorterName, $SorterDirection)
{
$this->Order = “cat_featured desc, started desc”;
$this->Order = CCGetOrder($this->Order, $SorterName, $SorterDirection,
array(“Sorter_title” => array(“cat_featured desc, title”, “”),
“Sorter_started” => array(“cat_featured desc, started”, “”),
“Sorter_asking_price” => array(“cat_featured desc, asking_price”, “”),
“Sorter_location” => array(“cat_featured desc, state_province ” . $SorterDirection . “, city_town”, “”)));
} [/code]

Pretty new to php so any suggestions are welcome, thanks

[upl-file uuid=3ea5db01-1e38-4844-b7a3-8815fc284676 size=66kB]rotate.jpg[/upl-file]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 16.2005 — I'm guessing that [b][font=courier]$this->Order = "cat_featured desc, started desc";[/font][/b] gets used in an ORDER BY clause of a SQL query. As there is no option to ORDER BY random, best suggestion I could come up with is to radomly chose to sort it ascending, descending, or unsorted (in database order). Replace the above line with this code, and see what happens (no guarantees it will work, not knowing for sure what the rest of the code does):
[code=php]
$nbr = rand(1,3);
switch($nbr)
{
case 1:
$this->Order = "cat_featured desc, started desc";
break;
case 2:
$this->Order = "cat_featured asc, started desc";
break;
default:
$this->Order = "started desc";
}
[/code]
×

Success!

Help @herronial spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...