Hi, I need to display the number of guitar tabs, drum tabs, bass tabs, lyrics for each band. I understand that query below gets the information but I don't know how to display it for each band. Here's the code so you can see what I'm on about:
$query = mysql_query("
SELECT
b.id
, t.filetype
, count(t.id) AS thecount
FROM
bands b
tabs t
WHERE
b.id=t.bid
GROUP BY
b.id
, t.filetype
LIMIT 0, 20
");
while($band = $db->fetch_array($query)) {
echo "band id: $band[id] | count: $band[thecount] | filetype: $band[filetype]<br />";
}
This is the output:
band id: 1 | count: 2 | filetype: Bass Tab
band id: 1 | count: 2 | filetype: Lyrics
band id: 2 | count: 85 | filetype: Guitar Tab
band id: 4 | count: 3 | filetype: Bass Tab
band id: 4 | count: 1 | filetype: Guitar Tab
band id: 4 | count: 25 | filetype: Lyrics
band id: 5 | count: 4 | filetype: Bass Tab
band id: 5 | count: 2 | filetype: Lyrics
band id: 6 | count: 1 | filetype: Lyrics
band id: 8 | count: 1 | filetype: Lyrics
band id: 10 | count: 1 | filetype: Bass Tab
band id: 11 | count: 1 | filetype: Bass Tab
band id: 12 | count: 8 | filetype: Guitar Tab
band id: 12 | count: 94 | filetype: Lyrics
band id: 13 | count: 1 | filetype: Bass Tab
band id: 13 | count: 4 | filetype: Guitar Tab
band id: 14 | count: 3 | filetype: Lyrics
band id: 15 | count: 1 | filetype: Bass Tab
band id: 17 | count: 11 | filetype: Bass Tab
band id: 17 | count: 1 | filetype: Guitar Tab
The values look correct to me but the bands come in seperate rows (for each filetype) of the array now. Therefore in the loop I did a check to see that the band had not been echoed in the previous statement:
while($band = $db->fetch_array($query)) {
if($bandid != $band['id]) {
echo "band id: $band[id] | count: $band[thecount] | filetype: $band[filetype]<br />";
}
$bandid = $band['id']
}
That was ok but now I wish to display the relative count for each filetype for that band. This is where I'm stuck because sometimes the value doesn't exist so I get errors.
I'd be greatful if someone could help. Thanks
$query = mysql_query("
SELECT
b.id
, t.filetype
, count(t.id) AS thecount
FROM
bands b
tabs t
WHERE
b.id=t.bid
GROUP BY
b.id
, t.filetype
LIMIT 0, 20
");
while($band = $db->fetch_array($query)) {
echo "band id: $band[id] | count: $band[thecount] | filetype: $band[filetype]<br />";
}
This is the output:
band id: 1 | count: 2 | filetype: Bass Tab
band id: 1 | count: 2 | filetype: Lyrics
band id: 2 | count: 85 | filetype: Guitar Tab
band id: 4 | count: 3 | filetype: Bass Tab
band id: 4 | count: 1 | filetype: Guitar Tab
band id: 4 | count: 25 | filetype: Lyrics
band id: 5 | count: 4 | filetype: Bass Tab
band id: 5 | count: 2 | filetype: Lyrics
band id: 6 | count: 1 | filetype: Lyrics
band id: 8 | count: 1 | filetype: Lyrics
band id: 10 | count: 1 | filetype: Bass Tab
band id: 11 | count: 1 | filetype: Bass Tab
band id: 12 | count: 8 | filetype: Guitar Tab
band id: 12 | count: 94 | filetype: Lyrics
band id: 13 | count: 1 | filetype: Bass Tab
band id: 13 | count: 4 | filetype: Guitar Tab
band id: 14 | count: 3 | filetype: Lyrics
band id: 15 | count: 1 | filetype: Bass Tab
band id: 17 | count: 11 | filetype: Bass Tab
band id: 17 | count: 1 | filetype: Guitar Tab
The values look correct to me but the bands come in seperate rows (for each filetype) of the array now. Therefore in the loop I did a check to see that the band had not been echoed in the previous statement:
while($band = $db->fetch_array($query)) {
if($bandid != $band['id]) {
echo "band id: $band[id] | count: $band[thecount] | filetype: $band[filetype]<br />";
}
$bandid = $band['id']
}
That was ok but now I wish to display the relative count for each filetype for that band. This is where I'm stuck because sometimes the value doesn't exist so I get errors.
I'd be greatful if someone could help. Thanks