DBUtill:: and left joining data  Top

  • 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:


    Code

    TABLE1: [uid] [name] [race]
    TABLE2: [rid] [laps] [time] [height] [weight]



    How to select from above tables into an array like below, in one query, given the $id to select from TABLE1?


    Code

    data (
        uid   => 23,
        name  => 'John Q. Public',
        race  => '1 Mile',
        stats => array(laps   => 'value',
                       time   => 'value',
                       height => 'value',
                       weight => 'value')
        )



    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
  • 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
  • There's this Wiki Entry for join info. The example I used works pulling from 3 tables.

    --
    Under Construction!
  • 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!

    :)

This list is based on the users active over the last 60 minutes.