格式化SQL/PHP生成的表

格式化SQL/PHP生成的表,php,html,sql,Php,Html,Sql,我不知道如何按照我想要的方式格式化生成的表: <?php $dbQuery=$db->prepare("select distinct tracks.title, albums.title, artists.name, basket.id ". "from basket,tracks,albums,artists ". "where basket.userID=:userID ".

我不知道如何按照我想要的方式格式化生成的表:

<?php
$dbQuery=$db->prepare("select distinct tracks.title, albums.title, artists.name, basket.id ".
                      "from basket,tracks,albums,artists ".
                      "where basket.userID=:userID ".
                      "and basket.paid='Y' ".
                      "and basket.trackID=tracks.id ".
                      "and albums.id=tracks.albumID ".
                      "and artists.id=tracks.artistID".
                      " order by artists.name, albums.title, tracks.title, basket.id");


$dbParams = array('userID'=>$_SESSION["currentUserID"]);                      
$dbQuery->execute($dbParams);
$numTracks=$dbQuery->rowCount();

if ($numTracks==0)
   echo "<h3>You have not made any purchases</h3>";
else {

?>

   <h2>Your Purchase History</h2>

   <table style="margin-left:15px" id="test">
   <tr><th>Artist</th><th>Album</th><th>Track</th></tr>

<?php 

   while ($dbRow=$dbQuery->fetch(PDO::FETCH_NUM)) {

      echo "<tr><td>$dbRow[2]</td><td>$dbRow[1]</td><td>$dbRow[0]</td><td>$dbRow[3]</td></tr>";
   }
}
?>

</table>
基本上,这将从字段、艺术家和相册中生成重复的值。我需要合并重复的艺术家/专辑,而不是一列中的多个相同的艺术家/专辑,它们被合并到一个单元格中

<table>
  <tr>
    <th>Artist1</th>
    <th>ablum1</th>
    <th>song1</th>
  </tr>
  <tr>
    <td>Artist1</td>
    <td>ablum2</td>
    <td>song1</td>
  </tr>
  <tr>
    <td>Artist2</td>
    <td>ablum1</td>
    <td></td>
  </tr>
</table>

This instead of above

<table>
  <tr>
    <th rowspan="2">Artist1</th>
    <th>ablum1</th>
    <th>song1</th>
  </tr>
  <tr>
    <td>ablum2</td>
    <td>song1</td>
  </tr>
  <tr>
    <td>Artist2</td>
    <td>ablum1</td>
    <td>song1</td>
  </tr>
</table>

Javascript似乎不起作用,因为我认为该表是在页面加载后生成的。

格式化示例数据和所需输出,以便更好地了解RDBMS是什么?是MySQL吗?在MySQL中使用PHPMyAdmin