PHP:注意:未定义的偏移量:0

时间:2016-04-03 09:58:25

标签: php mysql

我正在尝试在表中显示我的数据库结果,但现在我收到此消息。 Notice: Undefined offset: 0

这是我的代码:

$artistsql = "SELECT artist.artistName as 'artist.artistName', 
           artist.artistID as 'artist.artistID',
           publisher.pubName as 'publisher.pubName', 
           cd.CDTitle as 'cd.CDTitle',
           cd.CDID as 'cd.CDID'
    FROM tiptop_cd as cd
    INNER JOIN tiptop_artistcd as artistcd ON(artistcd.CDID = cd.CDID)
    INNER JOIN tiptop_artist as artist ON(artist.artistID = artistcd.artistID)
    INNER JOIN tiptop_publisher as publisher ON(publisher.pubID = cd.pubID)
    WHERE cd.CDTitle = :title";

$stmt = $db->prepare($artistsql);
$stmt->bindParam(":title", $_GET['title']);
$stmt->execute();
$results = $stmt->fetch(PDO::FETCH_ASSOC);
$details = $results[0];

$artistsql1 = "SELECT cd.CDTitle as 'cd.CDTitle'
    FROM tiptop_artistcd as artistcd
    INNER JOIN tiptop_cd as cd ON(cd.CDID = artistcd.CDID AND cd.CDID != :cd_id)
    WHERE artistcd.artistID = :artist_id";

$stmt = $db->prepare($artistsql1);
$stmt->bindParam(":artist_id", $details['artist.artistID']);
$stmt->bindParam(":cd_id", $details['cd.CDID']);
$stmt->execute();

echo "<table>".
     "<tr>".
     "<th>Artist Name</th>".
     "<th>Publisher</th>".
     "<th>Other Album</th>".
     "</tr>".

     "<tr>".
     "<td>".$details['artist.artistName']."</td>".
     "<td>".$details['publisher.pubName']."</td>".
     "<td>".$details['cd.CDTitle']."</td>".
     "</tr>";

while ($album = $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo "<tr style=\"cursor: pointer;\">";
    echo "<td></td>";
    echo "<td></td>";
    echo "<td>" . $album['cd.CDTitle'] . "</td>";
    echo "</tr>";
}

echo "</table";

错误显示在$details = $results[0];。我可以知道解决此问题的方法吗?因此我无法显示我的数据库结果。提前谢谢。

0 个答案:

没有答案