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

Support Forum

Start ::  Developers Corner ::  Module Development ::  DBUtill:: and left joining data

Moderated by: Support Team

Bottom
DBUtill:: and left joining data

  • Link to this postingPosted: 11.01.2008, 23:56
    Profile Homepage
    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

    -----
    AlarConcepts
  • Link to this postingPosted: 12.01.2008, 00:14
    Profile Homepage
    nestormateo
    rank:
    Professional 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! icon_wink

    -----
    - Mateo T. -
    Mis principios... son mis fines
  • Link to this postingPosted: 12.01.2008, 03:47
    Profile
    Topiatic
    rank:
    Professional 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!
  • Link to this postingPosted: 22.01.2008, 07:32
    Profile Homepage
    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!

    icon_smile

    -----
    AlarConcepts

Start ::  Developers Corner ::  Module Development ::  DBUtill:: and left joining data

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to Zikula