Jump to content

tricky db formatting question


Synergic

Recommended Posts

Ok i've got a CD catalog in a database. I have a cd table in the cd table i have a column for the artist, song and publisher. What i want to do is list each artist under their publisher so something like


Sony/BMG

  Artist 1
  Artist 2

Universal

  Artist 1
  Artist 2

I'm just having trouble approaching the problem of printing it out. How do i populate each artist under their respective publisher?
Link to comment
Share on other sites

[code]$publisher='';
$sql="SELECT artist, publisher FROM table ORDER by publisher DESC";
$resulte=mysql_query($sql) or die(mysql_error());
while ($row=mysql_fetch_array($result)) {
if ($row['publisher'] !== $publisher) {
 echo ("<H1>$row[publisher]</H1><Br>");
 $publisher=$row['publisher'];
}
echo($row['artist'].'<Br>');
}
?>[/code]

That should do the trick :)

Regards
Liam
Link to comment
Share on other sites

[quote author=ToonMariner link=topic=104209.msg415452#msg415452 date=1155565618]
Don't!

Just have a table of artist and a field for their publisher
[/quote]

for simplicity i have kept things in one table. i will fix the structure once i've figured this problem.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.