我正在构建一个音乐播放器,试图仅打印我的数据库的第一行,将其用作当前播放的播放列表的第一首歌曲,其他歌曲将存储在JQuery ListView
中。我收到此错误代码:
注意:第39行的C:\ Users \ Xaimer \ Desktop \ Interactive \ USBWebserver v8.6 \ root \ playlist.php中无法将类mysqli_result的对象转换为int。
第39行是if语句
<?php
echo'<p>Playlist</p>';
$sql="SELECT * FROM co1706assigment.tracks INNER JOIN co1706assigment.playlist ON tracks.track_id=playlist.track_id ";
$playlistcounter=mysqli_query($conn,"SELECT count(*) FROM co1706assigment.playlist")or die(mysqli_error($conn));
$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
while (($row = mysqli_fetch_array($result))&&($row1=mysqli_fetch_array($playlistcounter))) // it takes all the results from sql query
{
if($playlistcounter<2)
{
echo'<ul data-role="listview" data-filter="true">
<li><img id="song" src="'.$row["image"].'"/><p class="name">Track Name: </p>'.$row["name"].'
<p class="name">Album Name: </p>'.$row["album"].'
<p class="name">Sample</p>
<audio controls>
<source src="'.$row["sample"].'" type="audio/mpeg">
</audio>
</li>
</ul>';
}
}
echo'<p> My Playlist</p>';
while ($row = mysqli_fetch_array($result)) // it takes all the results from sql query
{
echo'<ul data-role="listview">
<li><a href="TrackDescription.php" data-ajax="false">'.$row["name"].'</a></li>
</ul>';
}
?>
答案 0 :(得分:0)
使用mysqli_fetch_assoc
查看
http://php.net/manual/en/mysqli-result.fetch-assoc.php
OR
像while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){}