Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
DBUtill:: and left joining data
  • Posted: 11.01.2008, 23:56
     
    alarconcepts
    rank:
    Professional 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:


    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


    --
    Photography | PHP | Other
  • Posted: 12.01.2008, 00:14
     
    nestormateo
    rank:
    Professional Professional
    registered:
     September 2006
    Status:
    online
    Posts:
    1450
    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
  • Posted: 12.01.2008, 03:47
     
    Topiatic
    rank:
    Professional Professional
    registered:
     November 2003
    Status:
    offline
    last visit:
    06.11.08
    Posts:
    1675
    There's this Wiki Entry for join info. The example I used works pulling from 3 tables.

    --
    Under Construction!
  • Posted: 22.01.2008, 07:32
     
    alarconcepts
    rank:
    Professional 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!

    :)

    --
    Photography | PHP | Other

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula