Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-17-2007, 09:49 PM
Junior Member
 
Join Date: Jul 2007
Posts: 11
Default fetchAll order_by and ASC/DESC?

Hello!

I'm starting to use the fetchAll method of the DBTable class and I'm wondering how to sort columns descending. I'm using a Sql Server database.

The signature of fetchAll is:
fetchAll($where, $order, $count, $offset);

It seems that $order must be a column name. I tried $order='ORDER BY Name DESC' and it didn't work. $order='Name' worked. If that's the case, how do you order descending?

Thanks!
- Bret
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-18-2007, 10:56 AM
Junior Member
 
Join Date: Sep 2007
Posts: 10
Default

Hi Bret.

I think you could try sending an array as parameter for the order:

array("Name" => "desc");

Hopefully this works for you.

Adrian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-18-2007, 08:10 PM
celavi's Avatar
Junior Member
 
Join Date: Jun 2007
Posts: 1
Default Zend_Db_Select

Try the Zend_Db_Select object!

/** $db Zend_Db_Adapter */

$select = $db->select()
->from('table', array('column1', 'column2'))
->order(array('column1 DESC', 'column2 ASC'));
$results = $db->fetchAll($select);

Regards,
AlesL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-18-2007, 09:54 PM
Junior Member
 
Join Date: Jul 2007
Posts: 11
Default

Thanks for your advice. Sending in an array for the order didn't work. I'd really love to use the DBTable interface for this. Any other solutions using DBTable?

Thanks!
- Bret
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-18-2007, 10:24 PM
Junior Member
 
Join Date: Jul 2007
Posts: 11
Default

Ah!! Wait! I think I'm down with the Zend_Db_Select object. I think that might be the golden ticket to happiness.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-29-2007, 02:17 PM
amos's Avatar
Junior Member
 
Join Date: Oct 2007
Posts: 1
Default

To specify the order just do something like:

$order = 'name';

and then use it in the fetchall as before (i've spent 2 hours tracking this down today myself) how you specify desc if you need it I'm not sure.
Can you spot a way of missing out the WHERE clause, at the moment I have

$where = $tablename->getAdapter()->quoteInto('LastName <> ?', '');

and then

$someView = $tablename->fetchAll($where, $order);

But the $where part is just a space holder.

Cheers
Amos
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-31-2007, 02:23 PM
Junior Member
 
Join Date: Oct 2007
Posts: 1
Default

Use: fetchAll(null, "fieldname ASC/DESC")

Grtz,
Demo
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:26 AM.