PHP请求到MySQL不工作 - 加入多个表 - 没有显示
我有一个PHP和MySQL的困难。我在MySQL的3个表:PHP请求到MySQL不工作 - 加入多个表 - 没有显示
- 艺术家(ID,这位演出)
- 专辑(ID,ALBUM_NAME,artist_id)
- 轨道(ID,artist_id,album_id,标题,链接,qr_code)
我想创建一个php请求到mysql,以显示链接到已经由用户选择的艺术家的所有专辑和曲目。
用户从下拉列表中选择艺术家,php获取artist_id。
我想下面的代码,但没有显示。
<?php $artist_id=$_POST['artist_id'];
$track_select=$connection->prepare('
SELECT *,
artist.id AS artist_id;
artist.artist_name AS artist_name,
album.id AS album_id;
album.album_name AS album_name
track.artist_id AS track_artist_id,
track.album_id AS track_album_id
FROM track
LEFT JOIN album ON album_id = track_album_id
LEFT JOIN artist ON artist_id = track_artist_id
WHERE (track_artist_id=:artist_id)');
$track_select->bindParam(':artist_id', $artist_id);
$track_select->execute();
while($donnees=$track_select->fetch())
{
echo $donnees['artist_name'].' '.$donnees['album_name'].' '.$donnees['title'].'<br />';
}
$track_select->closeCursor();
?>
我需要你的帮助,看看我犯了什么错误。
谢谢。
回答:
你不能在使用的列名ALIS或者在加入codnition
$track_select=$connection->prepare(' SELECT *,
artist.id AS artist_id;
artist.artist_name AS artist_name,
album.id AS album_id;
album.album_name AS album_name
track.artist_id AS track_artist_id,
track.album_id AS track_album_id
FROM track
LEFT JOIN album ON album.id = track.album_id
LEFT JOIN artist ON artist.id = track.artist_id
WHERE (tarck.artist_id=:artist_id)');
$track_select->bindParam(':artist_id', $artist_id);
$track_select->execute();
以上是 PHP请求到MySQL不工作 - 加入多个表 - 没有显示 的全部内容, 来源链接: utcz.com/qa/265782.html