RE: [PEAR] Query2XML problem with master-detail

From: Date: Sun, 11 Mar 2007 18:06:02 +0000
Subject: RE: [PEAR] Query2XML problem with master-detail
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-26816@lists.php.net to get a copy of this message
Hi Diana! Diana Quintal wrote: > > I'm trying to use the Query2XML package and am having > a problem returning a master-detail dataset. I copied > the examples from the documentation but both the left > join and the 2 separate selects only return 1 row of > my detail! If I run the exact same query against the > DB I get 9 detail rows back. I don't know why this > isn't working!! Here is the code for both ways that > I'm trying. I'm using Oracle if that makes a > difference. It's the same issue with both implementations: to get an element for each track record you have to use the track table's primary key (track_id?) for the option 'idColumn'. After all it is the track_id and not the album_id that uniquely identifies a track. In the first implementation change $options['elements']['tracks']['idColumn'] to 'track_id'. In the second, change $options['elements']['cuts']['idColumn'] to 'track_id'. (I'm referring to the second argument passed to the XML_Query2XML::getXML() method as $options) I hope this solves your problem, Lukas > > example with a left join: > $dom = $query2xml->getXML( > > "SELECT > > * > > FROM > > albums > LEFT JOIN tracks ON albums.album_id = > tracks.album_id > > where albums.album_id = '02521801652' ", > > array( > > 'rootTag' => 'music_library', > > 'rowTag' => 'album', > > 'idColumn' => 'album_id', > > 'elements' => array( > > 'album_id', > > 'album_name', > > 'artist', > > 'tracks' => array( > > 'rootTag' => 'tracks', > > 'rowTag' => 'track', > > 'idColumn' => 'album_id', > > 'elements' => array( > > 'album_id', > > 'track_title' > > ) > > ) > > ) > > ) > > ); > > example with 2 selects: > $dom = $query2xml->getXML( > "SELECT album_id,album_name, artist, genre_name, > release_date > FROM ALBUMS > WHERE album_id = '02521801652'", > > array( > > 'idColumn' => 'album_id', > 'rootTag' => 'album', > 'rowTag' =>'details', > 'elements' => array( > > 'title' => 'album_name', > 'genre' => 'genre_name', > 'artist'=> 'artist', > 'releasedate' => 'release_date', > 'cuts' => array( > 'sql' => array( > 'data' => array( > 'album_id' > ), > 'query' => 'SELECT > album_id,track_title from track where album_id = ?' > ), > 'sql_options' => array( > 'uncached' => true, > 'single_record' => false, > 'merge' => false, > 'merge_master' => false > ), > 'rootTag' => 'cuts', > 'rowTag' => 'cut', > 'idColumn' => 'album_id', > 'elements' => array( > 'title'=>'track_title' > ) > ) > ) > ) > ); > > This is the output: > <album> > <details> > <title>FOUR!</title> > <genre>Jazz</genre> > <artist>Hampton Hawes</artist> > <releasedate>1988-12-01 00:00:00</releasedate> > <cuts> > <cut> > <title>There Will Never Be Another You</title> > </cut> > </cuts> > </details> > </album> > > > > > ______________________________________________________________ > ______________________ > Need Mail bonding? > Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. > http://answers.yahoo.com/dir/?link=list&sid=396546091 > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.pear.general (#26816) next »