而且在 db.php ``` public function getDeviceList() { $arr = array(); $statement = $this->conn->prepare("SELECT id, device from utilities order by device ASC"); $statement->bind_result($id, $device); $statement->execute(); while ($statement->fetch()) { $arr[] = [ "id" => $id, "device" => $device]; } $statement->close();
return $arr;
}
public function getConfRoomList() { $arr = array(); $statement = $this->conn->prepare("SELECT id, name, utilities from rooms order by name ASC"); $statement->bind_result($id, $name, $utilities); $statement->execute(); while ($statement->fetch()) { $arr[] = [ "id" => $id, "name" => $name, "utilities" => $utilities]; } $statement->close();
return $arr;
}
根据接受的解决方案编辑更新的代码:
我在db.php中添加了以下内容:
public function joinDevRoom() { $arr = array(); $statement = $this->conn->prepare("SELECT r.name,GROUP_CONCAT(u.device) FROM room r LEFT JOIN utilities u ON FIND_IN_SET(u.id,r.utilities)>0 GROUP BY r.id"); $statement->bind_result($id, $utilities); $statement->execute(); while ($statement->fetch()) { $arr[] = [ "id" => $id, "utilities" => $utilities]; } $statement->close();
22条答案
按热度按时间dy1byipe1#
wfypjpf42#
jdzmm42g3#
4c8rllxm4#
s4chpxco5#
试试这个
quhf5bfb6#
368yc8dk7#
irlmq6kh8#
a6b3iqyw9#
lbsnaicq10#
uqzxnwby11#
kqqjbcuj12#
表:公用设施
|
6qqygrtg13#
ccgok5k514#
qnakjoqk15#
我想打印这样的东西:
Room1: Speakers, Smart TV, Web camera
到目前为止,我得到的是confroomreport.php:而且在
db.php
```public function getDeviceList()
{
$arr = array();
$statement = $this->conn->prepare("SELECT id, device from utilities order by device ASC");
$statement->bind_result($id, $device);
$statement->execute();
while ($statement->fetch()) {
$arr[] = [ "id" => $id, "device" => $device];
}
$statement->close();
public function getConfRoomList()
{
$arr = array();
$statement = $this->conn->prepare("SELECT id, name, utilities from rooms order by name ASC");
$statement->bind_result($id, $name, $utilities);
$statement->execute();
while ($statement->fetch()) {
$arr[] = [ "id" => $id, "name" => $name, "utilities" => $utilities];
}
$statement->close();
}
public function joinDevRoom()
{
$arr = array();
$statement = $this->conn->prepare("SELECT r.name,GROUP_CONCAT(u.device) FROM room r LEFT JOIN utilities u ON FIND_IN_SET(u.id,r.utilities)>0 GROUP BY r.id");
$statement->bind_result($id, $utilities);
$statement->execute();
while ($statement->fetch()) {
$arr[] = [ "id" => $id, "utilities" => $utilities];
}
$statement->close();
}