1 回答

TA貢獻(xiàn)1770條經(jīng)驗(yàn) 獲得超3個(gè)贊
正如我所見,您問題中的問題是您正在嘗試計(jì)算一個(gè)非數(shù)組或不可數(shù)的對象。
思緒
在您的整個(gè)代碼中,您沒有編寫
count()
似乎導(dǎo)致問題的原因,為什么?$q->row();
當(dāng)您自己將結(jié)果限制為 1 時(shí),為什么還需要計(jì)數(shù)// as you said the problem is here $row = $q->row();
可能的解決方案
當(dāng)您使用row()
ie時(shí),$q->row();
您會(huì)得到一個(gè)不可數(shù)的對象,
// row() dummy data
stdClass Object
(
? ? [id] => 15
? ? [event_id] => 3
? ? [event_image] => c1fa8a5d5505047251fd928aa312b16c.jpg
)
但是當(dāng)你使用result()ie時(shí)$q->result();,它會(huì)產(chǎn)生一個(gè)對象數(shù)組,或者在 的情況下result_array(),一個(gè)數(shù)組數(shù)組,即使你將它們限制為一個(gè)。
// result() dummy data -- same as result_object()
(
? ? [0] => stdClass Object
? ? ? ? (
? ? ? ? ? ? [id] => 15
? ? ? ? ? ? [event_id] => 3
? ? ? ? ? ? [event_image] => c1fa8a5d5505047251fd928aa312b16c.jpg
? ? ? ? )
)
// result_array() dummy data
Array
(
? ? [0] => Array
? ? ? ? (
? ? ? ? ? ? [id] => 15
? ? ? ? ? ? [event_id] => 3
? ? ? ? ? ? [event_image] => c1fa8a5d5505047251fd928aa312b16c.jpg
? ? ? ? )
)
它們現(xiàn)在都是一個(gè)數(shù)組,因此是可數(shù)的。
所以,如果你必須計(jì)算,使用此外,如果你想計(jì)算“結(jié)果”的數(shù)量,你可以使用which will return 3 here。
$q->row();
count((array) ($q->row()));
{id}, {event_id}, {event_image}
希望對你有幫助。
- 1 回答
- 0 關(guān)注
- 169 瀏覽
添加回答
舉報(bào)