我有一张桌子" items"有音乐作品,标题如" title" "作曲家" "描述" ..每个作曲家的各种片段..尝试将PHP脚本发送到SELECT * from items, order by "composer"
但在作曲家的while
中生成一个标题,然后输出他们工作的所有行,等等下一个..即:
ITEMS TABLE
-------------------------------
David Drury | piece 1 | info
-------------------------------
David Drury | piece 2 | info
--------------------------------
Alfonzo Smith | piece 1 | info
--------------------------------
David Drury | piece 3 | info
David Drury
Alfonzo Smith
我可以在一张桌子上这样做吗?或者我可以为作曲家创建一个表,其中的连接可以看到作曲家,输出标题,然后从项目表中的连接中输出片段?
答案 0 :(得分:0)
得到它..子查询。对于这可能有帮助的人来说,这就是我所使用的:
$sqlCommand = "SELECT DISTINCT Composer FROM items";
$query = mysqli_query($db_conx, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$Composer = $row["Composer"];
echo '<h2>'.$row["Composer"].'</h2>';
$sqlCommand2 = "SELECT * FROM items WHERE Composer = '$Composer'";
$query2 = mysqli_query($db_conx, $sqlCommand2) or die (mysqli_error());
while ($row2 = mysqli_fetch_array($query2)) {
$idPart = $row2["idPart"];
$Composer = $row2["Composer"];
$Title = $row2["Title"];
$Opus = $row2["Opus"];
$Instrumentation = $row2["Instrumentation"];
$Type = $row2["Type"];
$ISMN = $row2["ISMN"];
$RRP = $row2["RRP"];
$information = $row2["information"];
echo '<h5>'.$Title.' - '.$information.'</h5>';
}
}