我这里有一个mysql查询来显示jquery accordion中数据库的信息。我使用GROUP_CONCAT对供应商和代码进行分组。
这是我的表结构。
id | supplier | code
--------------------------
1 | DELL | 9001
2 | DELL | 9002
3 | HP | 3201
4 | HP | 4112
查询
$mysqli = new mysqli("localhost", "root", "", "table");
$result = $mysqli->query("Select (SELECT group_concat(DISTINCT code) FROM table) as a, (SELECT group_concat(DISTINCT supplier) FROM table) as b");
while($row = $result->fetch_assoc()){
echo '<h3>'.$row['b'].'</h3>';
echo '<div>'.$row['a'].'</div>';
}
导致localhost
a | b
----------------
9001,9002 | DELL
我期望在每个手风琴div的html中输出
DELL
9001
9002
-----
HP
3201
4112
这样我就可以为每个代码建立一个链接,比如
<a href="">'.$row['a'].'</a>
任何帮助都会表示赞赏。