Forum Moderators: coopster
$temp = new db();
$temp->select_db($dbname);
$list = $temp->browse_by_letter($table, $letter);
$details = $temp->get_artist($table, $artist_id);
function browse_by_letter($table, $leter)
{
$res = mysql_query("select artist, MIN(id) as id from $table where artist like '$leter%' group by artist order by artist asc");
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
extract($row);
$artist = $row['artist'];
$id = $row['id'];
$res1 = mysql_query("select count(song) as count from $table where artist=\"$artist\"");
while ($row1 = mysql_fetch_array($res1, MYSQL_ASSOC)) {
extract($row1);
} //while
$res2 = mysql_query("select song, viewed from $table where artist=\"$artist\" order by viewed asc");
while ($row2 = mysql_fetch_array($res2, MYSQL_ASSOC)) {
extract($row2);
$song = $row2['song'];
$viewed = $row2['viewed'];
} //while
$this->result[$id][$artist][$count][$song] = $viewed;
} //while
return $this->result;
}
function get_artist($table, $artist_id)
{
$artist_tmp = $this->get_artist_name($table, $artist_id);
$res = mysql_query("select artist, id,song from $table where artist=\"$artist_tmp\"");
while ($row = mysql_fetch_array($res)) {
$artist = $row['artist'];
$song = $row['song'];
$id = $row['id'];
$this->result[$artist][$id] = $song;
} //while
return $this->result;
}
function get_artist_name($table, $artist_id)
{
$res = mysql_query("select artist from $table where id='$artist_id'");
while($row = mysql_fetch_array($res, MYSQL_ASSOC))
$this->artistname = $row['artist'];
return $this->artistname;
}
$res = mysql_query("select artist, MIN(id) as id from $table where artist like '$leter%' group by artist order by artist asc");
will return just one id - the smallest one.
Instead I would run this query:
$res = mysql_query("select artist, id from $table where artist like '$leter%' group by artist"); //group already orders the rows and order by is omitted.
Also in the second you can use one query:
SELECT a.artist, s.id, s.song from artist a, song s WHERE s.artist=a.name AND a.id='$artist_id';
And I would store in table song artist as ID not as name.
Then
SELECT a.artist, s.id, s.song from artist a, song s WHERE s.artist=a.id AND a.id='$artist_id';
Regards
Michal