Start ::
Developers Corner ::
Module Development ::
DBUtill:: and left joining data
Moderated by: Support Team
-
- rank:
-
Professional
- registered:
- April 2004
- Status:
- offline
- last visit:
- 21.01.08
- Posts:
- 2723
After trying quite a few variations to join data between tables when selecting via DBUtil::, having trouble with various mysql errors. If there are 2 tables setup like this:
How to select from above tables into an array like below, in one query, given the $id to select from TABLE1?
The $data['stats'] variable would be made on the fly presumably, and essentially consist of the same data that would result from "SELECT * FROM TABLE2 WHERE rid='$uid'". This is a situation where leftjoin should be used, right?
I've looked over the selectObject* and selectExpandedObject* functions and have read the $joinInfo info at the top of the class, but can't get the syntax right...
Any assistance is appreciated!
Thanks,
- John
-----
AlarConcepts -
- rank:
-
Professional
- registered:
- September 2006
- Status:
- offline
- last visit:
- 27.08.08
- Posts:
- 1177
Hi Alar!
the latest trouble that i had with DBUtil::selectExpandedObject was a problem with the joinInfo...
it's an array of the "arrays of joins", not purely an array with the join info... i mean:
Note the bold part:
$joinInfo[ ] = array(
'join_table' => TABLE2,
'join_field' => array('laps', 'time', 'height', 'weight'),
'object_field_name' => array('laps', 'time', 'height', 'weight'), // no name override
'compare_field_table' => 'uid',
'compare_field_join' => 'rid'
);
$where = "...
$orderBy = "...
$result = DBUtil::selectExpandedObjectArray(TABLE1, $joinInfo, $where, $orderBy);
I guess that can do the trick...
i don't know if the rename allows to create an array, like:
'object_field_name' => array('stats.laps', 'stats.time', 'stats.height', 'stats.weight')
i think it's not supported...
Good luck with that!
-----
- Mateo T. -
Mis principios... son mis fines -
- rank:
-
Professional
- registered:
- November 2003
- Status:
- offline
- last visit:
- 24.08.08
- Posts:
- 1609
There's this Wiki Entry for join info. The example I used works pulling from 3 tables.
-----
Under Construction! -
- rank:
-
Professional
- registered:
- April 2004
- Status:
- offline
- last visit:
- 21.01.08
- Posts:
- 2723
Sorry so late in getting back to you... thanks for the advices guys. I plan to give it a try in the next week or so...wish me luck!
-----
AlarConcepts
Start ::
Developers Corner ::
Module Development ::
DBUtill:: and left joining data
