ArticleCollection - order by RAND()

Gesperrt
szabo.b.gabor
Beiträge: 1
Registriert: Mi 11. Feb 2009, 12:52
Kontaktdaten:

ArticleCollection - order by RAND()

Beitrag 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
OliverL
Beiträge: 870
Registriert: Do 28. Jun 2007, 09:28
Kontaktdaten:

Re: ArticleCollection - order by RAND()

Beitrag 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
Gesperrt