Jump to content

[SOLVED] Simple query help


mrjonnytou

Recommended Posts

I would like to sort the result from the following query in descending order:

 

//$sort is a the name of a table to sort by

public function sortActiveByColumn($sort)

    {

        $select = $this->select()->from($this)

                                ->where('completed LIKE ?', 0)

                                ->order($sort);

 

        return $this->fetchAll($select);

    }

 

I've tried:

      ->order('$sort, DESC');

----------------------------

      ->order($sort)

      ->desc;

----------------------------

...and other variations.

 

Any guidance would be helpful/appreciated as I'm not sure of the syntax.

 

Regards,

 

Link to comment
https://forums.phpfreaks.com/topic/113910-solved-simple-query-help/
Share on other sites

public function sortActiveByColumn($sort)

    {

        $select = $this->select()->from($this)

                                ->where('completed LIKE ?', 0)

                                ->order by $sort DESC;

 

        return $this->fetchAll($select);

    }

It Works! Thanks a lot.

 

I can't believe thats all it was. Much appreciated.

 

The working code:

 

public function sortActiveByColumn($sort)

    {

        $select = $this->select()->from($this)

                                ->where('completed LIKE ?', 0)

                                ->order("$sort desc");

        return $this->fetchAll($select);

    }

 

Regards,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.