Page 1 of 1

query help

Posted: Sun Aug 24, 2003 9:03 am
by CrazyJimmy
Hi,

I have a db with for music collection with 2 tables. One for title information and another table with just tracks. I can get a query to return a title and all the associated tracks but the title is displayed on every line too. Is it possible to display the title once and the associated tracks?

Posted: Mon Aug 25, 2003 8:58 pm
by JAM
It depends on how you script it... And example:

Code: Select all

$result = mysql_query("select a,b from tunes where id = '1'");
 $title = '';
 while ($row = mysql_fetch_array($result)) {
  // check if $title  is set, if not, set it and display it.
  // else, do nothing.
  if (empty($title)) {
    $title = $row[0];
    echo $row[0];
   }
   // display the track...
   echo $row[1];
 }

Re: query help

Posted: Tue Aug 26, 2003 10:09 am
by ericsodt
Thats a SQL problem... do an outter query to pull back ONE record for the title and its associated tracks(MANY tracks, ONE record title) = OUTTER QUERY.


ie:

select
blah,
blah2
from
oneTable_t a,
2ndTable_t b
where
a.id(+) = b.id

CrazyJimmy wrote:Hi,

I have a db with for music collection with 2 tables. One for title information and another table with just tracks. I can get a query to return a title and all the associated tracks but the title is displayed on every line too. Is it possible to display the title once and the associated tracks?