<?php
$db = new mysqli(//editted out db credentials);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = "SELECT m.ID, m.Title, GROUP_CONCAT(a.Title) AS Artist
FROM mp3s m
LEFT JOIN artist_relations ar ON ar.mp3ID = m.ID
LEFT JOIN artists a ON a.ID = ar.artistID
GROUP BY m.ID
ORDER BY ID
LIMIT 0,30;
";
if($result = $db->query($sql)){
echo "<table>";
while($row = $result->fetch_assoc()){
echo "<tr>";
echo "<td>".$row['Title']."</td>";
echo "<td>".$row['Artist']."</td>";
echo "</tr>";
}
echo "</table>";
}
?>
Run Code Online (Sandbox Code Playgroud)
该查询正常工作,但是速度非常慢。 …