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

Dizkus

Bottom
help with get and getAll functions
  • Posted: 04.07.2005, 03:48
     
    cannibus
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    20.09.08
    Posts:
    401
    ok, i been trying to get this all weekend, to no avail



    what i have is a table for songs, in the table is a field with an artist id,


    i also have an artist table, with an artist name and an id,


    what would be the best way to get the artist name displayed, in a getall_song function, if you guys need any code or extra info let me know,


    here is the getall_song() function

    Code

    extract($args);

        if (!isset($startnum) || !is_numeric($startnum)) {
            $startnum = 1;
        }
        if (!isset($numsongs) || !is_numeric($startnum)) {
            $numsongs = -1;
        }

        $items = array();

        if (!pnSecAuthAction(0, 'RiddimDB::', '::', ACCESS_OVERVIEW)) {
            return $items;
        }

        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        $songtable = $pntable['riddimdb_song'];
        $songcolumn = &$pntable['riddimdb_song_column'];
        $artisttable = $pntable['riddimdb_artist'];
        $artistcolumn = &$pntable['riddimdb_artist_column'];

        $sql = "SELECT $songcolumn[sid],
                       $songcolumn[rid],
                       $songcolumn[aid],
                       $songcolumn[pid],
                       $songcolumn[cid],
                       $songcolumn[sname],
                       $songcolumn[lyric],
                       $songcolumn[album],
                       $songcolumn[year],
                       $songcolumn[label]
                FROM $songtable
                ORDER BY $songcolumn[sname]"
    ;

        $result = $dbconn->SelectLimit($sql, $numsongs, $startnum-1);

        if ($dbconn->ErrorNo() != 0) {
            pnSessionSetVar('errormsg', _GETFAILED);
            return false;
        }

        for (; !$result->EOF; $result->MoveNext()) {
            list($sid, $rid, $aid, $pid, $cid, $sname, $lyric, $album, $year, $label) = $result->fields;
            if (pnSecAuthAction(0, 'RiddimDB::', "$sname::$sid", ACCESS_OVERVIEW)) {
                $items[] = array('sid' => $sid,
                                 'rid' => $rid,
                                 'aid' => $aid,
                                 'pid' => $pid,
                                 'cid' => $cid,
                                 'sname' => $sname,
                                 'lyric'     => $lyric,
                                 'album'      => $album,
                                 'year'    => $year,
                                 'label'    => $label);
            }
        }

        $result->Close();
        return $items;
  • Posted: 04.07.2005, 07:58
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    You'll need a join statement. The MySQL docs on joins are hard to understand, so you might do best to do a google search on tutorials for them. I'm still trying to wrap my head around them.
  • Posted: 04.07.2005, 08:39
     
    cannibus
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    20.09.08
    Posts:
    401

    jediping

    You'll need a join statement. The MySQL docs on joins are hard to understand, so you might do best to do a google search on tutorials for them. I'm still trying to wrap my head around them.



    hmmm, i remember joins in a class i took, never quite understood em. :( thanks for the reply. now that i think about it, i REALLY didnt like joins. lol




    life was so much less complicated as a end user icon_redface
  • Posted: 04.07.2005, 14:38
     
    alarconcepts
    rank:
    Professional Professional
    registered:
     April 2004
    Status:
    offline
    last visit:
    21.01.08
    Posts:
    2723
    The PHP and MySQL forums at sitepoint.com are da bomb when you need help! Tons of people who know this stuff like their A,B,C's...

    --
    Photography | PHP | Other
  • Posted: 05.07.2005, 05:40
     
    cannibus
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    20.09.08
    Posts:
    401
    i found this site VERY helpful, just thought i'd share the link!




    it explains the various JOIN options that are offered, and is easy to read.


    http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.shtml




    PS i also checked out that site alar, thanks alot!
  • Posted: 05.07.2005, 23:18
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    Thanks for that link! I think I ran across the site a while back and forgot to bookmark it, despite how much easier it made things! :)

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula