[Typo3-dev] ORDER BY RAND() support in pi_list_query()

Martin T. Kutschker Martin.no5pam.Kutschker at blackbox.n0spam.net
Tue May 11 18:34:29 CEST 2004


Christian Zehaczek wrote:
> Dear TYPO3 Developers,
> 
> what about this little hotfix in tslib_pibase::pi_list_query()
> 
> --- snip ---
>     if
> (t3lib_div::inList($this->internal["orderByList"],$this->internal["orderBy"]
> )) {
>      // 2004-05-10: Do not prepend table name when sorting by rand(),
> ignoring sorting flag
>      ($this->internal["orderBy"] <> "rand()")
>       ? $query.= " ORDER BY
> ".$table.".".$this->internal["orderBy"].($this->internal["descFlag"]?"
> DESC":"").chr(10)
>       : $query.= " ORDER BY ".$this->internal["orderBy"].chr(10);
>     }
> --- snap ---
> 
> This one allowed me to give "rand()" as sorting field, maybe anyone does
> like it.

Why not generalize it to support arbitrary calculated SELECT clause 
columns? Prependening the table name will disable sorting after any 
expression not just "rand() AS random_col", so I suggest something like 
this:

--- snip ---
if (t3lib_div::inList($this->internal["orderByList"],
     $this->internal["orderBy"])) {

   $query.= " ORDER BY " .
     ($this->internal["orderByExpression"] ? "" : "$table.") .
     $this->internal["orderBy"] .
     ($this->internal["descFlag"] ? " DESC" : "") .
     chr(10);
}
--- snap ---

Masi

PS: What's the line feed for?





More information about the TYPO3-dev mailing list