php - 我想循环创建基于 Select2 数据格式的分组数据
问题描述
我想通过 HardwareTypeCode 循环创建基于 select2 数据格式的分组数据。
我不知道如何处理 PHP。
SQL查询:
SELECT historyhardwaretb.HardwareID,
hardwaretb.HardwareCode,
hardwaretb.IPAddress,
hardwaretb.MacAddress,
hardwaretypetb.HardwareTypeCode,
historyhardwaretb.EmployeeID,
historyhardwaretb.Description
FROM historyhardwaretb
INNER JOIN hardwaretb ON historyhardwaretb.HardwareID = hardwaretb.HardwareID
INNER JOIN hardwaretypetb ON hardwaretb.HardwareTypeID = hardwaretypetb.HardwareTypeID
PHP:
while ($row = $sql->fetch_assoc()) {
$jsonGroup[$i]['text'] = $row['HardwareTypeCode'];
}
预期的 select2 分组数据格式结果:
{
"jsonGroup": [
{
"text": "PC",
"children" : [
{
"id": 1,
"text": "Option 1.1"
},
{
"id": 2,
"text": "Option 1.2"
}
]
},
{
"text": "NB",
"children" : [
{
"id": 3,
"text": "Option 2.1"
},
{
"id": 4,
"text": "Option 2.2"
}
]
}
],
"pagination": {
"more": true
}
}
解决方案
推荐阅读
- sql - 在 SQL 中查找周数
- nlp - NLP:哪些是与动词相关的依赖标签?
- ios - 如何在故事板中创建的 UITableView 中隐藏单元格?
- ruby-on-rails - 是否有一次销毁所有子记录的选项?
- c - 将输出从函数重定向到 C 中的文件
- python - 发现样本数量不一致的输入变量:[14559, 1455900]
- r - 选择在 R 中至少有一个非缺失值的组
- loops - VBA 循环使用 F8 工作,但在自由运行时不工作
- postgresql - Postgresql 简单的 IF ELSE 语句
- javascript - 全局标签替换对象/数组中的文本(标签->值)javascript