亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法訪問字符串變量(“1”)上的屬性(“名稱”)

無法訪問字符串變量(“1”)上的屬性(“名稱”)

PHP
胡子哥哥 2022-01-08 17:29:18
我怎樣才能得到名字而不僅僅是id?這實際上是我在數據表 中的內容:當前數據表但我需要的是顯示區域的名稱而不是 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>但我收到以下錯誤:無法訪問字符串變量(“1”)上的屬性(“名稱”)。關于修復它的任何想法或建議?或者有什么問題?這是我在轉儲 AuditsByArea 時得到的:    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貢獻1818條經驗 獲得超11個贊

在您寫的評論中,您的查詢是:


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;

您可以通過以下方式在循環中訪問它:


{{ audit.area_name }}

但是請注意,您使用的是普通的 php 數組,帶有“手動”sql 查詢,并且沒有教義的 ORM 提供的任何功能。


查看完整回答
反對 回復 2022-01-08
  • 1 回答
  • 0 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號