Jump to content


Photo

tricky db formatting question


  • Please log in to reply
5 replies to this topic

#1 Synergic

Synergic
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 14 August 2006 - 02:22 PM

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?

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 14 August 2006 - 02:26 PM

Don't!

Just have a table of artist and a field for their publisher
follow me on twitter @PHPsycho

#3 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 14 August 2006 - 02:35 PM

Don't!

Just have a table of artist and a field for their publisher

u can do 1 field, and run a MySQL query with php to get the result u want
Tell me the problem, I will try tell you the solution

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 14 August 2006 - 02:36 PM

$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>');
}
?>

That should do the trick :)

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 Synergic

Synergic
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 14 August 2006 - 03:00 PM

Don't!

Just have a table of artist and a field for their publisher


for simplicity i have kept things in one table. i will fix the structure once i've figured this problem.

#6 Synergic

Synergic
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 14 August 2006 - 03:06 PM

nerver mind, my bad :) thanks for the help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users