- Moderated by:
- Support
-
- rank:
-
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; -
- rank:
-
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. -
- rank:
-
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
-
- rank:
-
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 -
- rank:
-
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!
