Seite 1 von 1

ArticleCollection - order by RAND()

Verfasst: Mi 11. Feb 2009, 13:00
von szabo.b.gabor
Hi all!

sorry for writing things in english, my deutsch is crappy. in earlier versions of contenido it was allowed to use RAND() for the order option. now it is not available, because you bind the '$this->order' value to a table

so contenido/classes/class.article.php around row 578 should be changed from this

Code: Alles auswählen

        if (!$this->offline)
        {
            $sql .= ' AND a.online = 1 ';
        }

        $sql .= ' ORDER BY a.'.$this->order.' '.$this->direction.'';

        $this->db->query($sql);
to something like this

Code: Alles auswählen

        if (!$this->offline)
        {
            $sql .= ' AND a.online = 1 ';
        }

        if(this->order=="RAND()"){
                $sql .= ' ORDER BY '.$this->order.' '.$this->direction.'';
        }else{
                $sql .= ' ORDER BY a.'.$this->order.' '.$this->direction.'';
        }

        $this->db->query($sql);
Contenido is cool! go on!
gabor

Re: ArticleCollection - order by RAND()

Verfasst: Do 12. Feb 2009, 13:24
von OliverL
... and my english is crappy. :mrgreen:

Where is this used?

Your Code ist good.
But Random "Rand()" isn't needed $this->direction
and the following code is easy to read (for me :) )

Code: Alles auswählen

if (!$this->offline)
{
      $sql .= ' AND a.online = 1 ';
}

if(this->order=="RAND()"){
      $sql .= ' ORDER BY RAND()';
}else{
      $sql .= ' ORDER BY a.'.$this->order.' '.$this->direction.'';
}

$this->db->query($sql);
mfg OliverL