我怎樣才能得到名字而不僅僅是id?這實(shí)際上是我在數(shù)據(jù)表 中的內(nèi)容:當(dāng)前數(shù)據(jù)表但我需要的是顯示區(qū)域的名稱而不是 id。我試圖這樣做:<table aria-describedby="dataTable_info" cellspacing="0" class="table table-hover dataTable" id="dataTable" role="grid" style="width:100%;" width="100%"> <thead> <tr> <th>Areas</th> <th>Auditorias</th> </tr> </thead> <tbody> {% for audit in auditsByArea %} <tr> <td>{{ audit.id_Area.name }}</td> <td>{{ audit.Audits }} <input style="width:0.8cm; height:0.8cm;background-color:##E4E8E9; border-radius: 8px; border-color:#3A93B2" class ="mx-2" data-id="4" data-area="{{ audit.id_Area }}"data-responsible="4" data-startDate="<?php date('n/d/Y');?>" id="auditBtn" name="auditBtn" type='text' readonly data-toggle="modal" data-target="#auditModal"></input></td> </tr> {% endfor %} </tbody> </table>但我收到以下錯(cuò)誤:無(wú)法訪問(wèn)字符串變量(“1”)上的屬性(“名稱”)。關(guān)于修復(fù)它的任何想法或建議?或者有什么問(wèn)題?這是我在轉(zhuǎn)儲(chǔ) AuditsByArea 時(shí)得到的: array (size=3) 0 => array (size=2) 'id_Area' => string '1' (length=1) 'Audits' => string '1,2,3,4' (length=7) 1 => array (size=2) 'id_Area' => string '3' (length=1) 'Audits' => string '12,11,10,9' (length=10) 2 => array (size=2) 'id_Area' => string '5' (length=1) 'Audits' => string '17,18,19,20' (length=11)
1 回答

慕尼黑8549860
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
在您寫的評(píng)論中,您的查詢是:
SELECT id_Area, GROUP_CONCAT(id_Audit) as Audits
FROM helios.fsa_audits
WHERE id_Auditor='$AuditorId'
GROUP BY id_Area;
添加要輸出的信息:
SELECT id_Area, area.Name as area_name, GROUP_CONCAT(id_Audit) as Audits
FROM helios.fsa_audits
LEFT JOIN helios.fas_areas area USING (id_Area)
WHERE id_Auditor='$AuditorId'
GROUP BY id_Area;
您可以通過(guò)以下方式在循環(huán)中訪問(wèn)它:
{{ audit.area_name }}
但是請(qǐng)注意,您使用的是普通的 php 數(shù)組,帶有“手動(dòng)”sql 查詢,并且沒(méi)有教義的 ORM 提供的任何功能。
- 1 回答
- 0 關(guān)注
- 151 瀏覽
添加回答
舉報(bào)
0/150
提交
取消