Re: DB_DataObject sorting links-results
| From: | Alan Knowles | Date: | Tue, 14 Jan 2003 01:30:39 +0000 |
| Subject: | Re: DB_DataObject sorting links-results | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-3293@lists.php.net to get a copy of this message | ||
Wolfram (comments in-line)
i got a question about DataObjects. after getting the linked tables, i would like to have the multiple results sorted by a column how do i do that?
what i got now is without sorting
$contact = new DataObjects_Contact2tree;
$contact->contactTree_id = $session->temp->folder->id;
$contact->find();
while( $contact->fetch() )
{
// link the column 'contact_id' to the table 'contact'
// which contains columns like 'name' 'surname' etc.
$contact->getLinks();
print_r($contact);
}
personally I would just cop out and use the query(), method directly.. - it's in there because sometimes writing the SQL manually is easier to read and understand than autobuilding it...
It may be worth looking at the joinAdd() stuff for this.. It's beta quality at the moment, and needs a bit more thought about how to deal with things like crosstable queries (that perhaps dont need joins...)
I should write the docs for this, - and stick a warning in there.. 'using this method may make your code very difficult to understand - use with care'
It still needs more thoughts about how to deal with the return values, (I would like it to do something like getLinks(), and make subobjects with the data.
otherwise,
$data[$contact->_contact->name] = $contact;
then array_sort on the result..
Regards
Alan
i.e. i want to sort by 'contact.name', is that possible? if so, how?
the query would be:
SELECT * FROM contact2tree ct,contact c
WHERE ct.contact_id=c.id
ORDER BY c.name
but since i am reading the contact2tree table first, when using the DataObject i have no idea how to sort by the content of a table i will 'link'/'join' later-- Can you help out? Need Consulting Services or Know of a Job? http://www.akbkhome.com