第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在循環(huán)中中斷索引數(shù)組并在php中使用

如何在循環(huán)中中斷索引數(shù)組并在php中使用

PHP
達(dá)令說(shuō) 2023-07-21 18:17:31
我在索引數(shù)組中有兩個(gè)值(bookingId),現(xiàn)在我想使用這些值更新查詢(xún),但現(xiàn)在無(wú)法在循環(huán)中中斷數(shù)組,我想運(yùn)行更新查詢(xún)(根據(jù)數(shù)組中的計(jì)數(shù)值)這是我的代碼,我錯(cuò)在哪里?$bookingIds; // contaning two values 176,190$counts = count($bookingIds);  // counting array valuesfor ($x = 1; $x <= $counts; $x++)     {        $data = array('approved' => "1");        $this->db->where('bookingId', $bookingIds);        $this->db->update('notifications', $data);    }
查看完整描述

3 回答

?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊

我認(rèn)為你應(yīng)該在循環(huán)時(shí)提及數(shù)組的索引。并且你$x必須從0


$bookingIds; // contaning two values 176,190

$counts = count($bookingIds);  // counting array values

for ($x = 0; $x < $counts; $x++) 

    {

        $data = array('approved' => "1");

        $this->db->where('bookingId', $bookingIds[$x]);

        $this->db->update('notifications', $data);

    }


查看完整回答
反對(duì) 回復(fù) 2023-07-21
?
慕萊塢森

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

使用 foreach 來(lái)重構(gòu)上述內(nèi)容以消除整個(gè)索引問(wèn)題將是


$data = array('approved' => "1");

foreach ($bookingsIds as $bookingId )

{

    $this->db->where('bookingId', $bookingId);

    $this->db->update('notifications', $data);

}


查看完整回答
反對(duì) 回復(fù) 2023-07-21
?
慕神8447489

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超1個(gè)贊

看起來(lái)你正在使用一個(gè)框架;如果它提供了一個(gè)whereIn()方法,使用它會(huì)更有效(運(yùn)行更少的 SQL 查詢(xún)):

$data = ['approved' => '1'];$this->db
    ->whereIn('bookingId', $bookingIds)
    ->update('notifications', $data);


(請(qǐng)注意,您不能將數(shù)千個(gè)值放入這樣的“where in”子句中,因?yàn)椴樵?xún)會(huì)很大。就我個(gè)人而言,我會(huì)分塊處理此類(lèi)內(nèi)容,例如每個(gè)查詢(xún) 500 條記錄。)

(另外,如果“where in”數(shù)組(此處為 )為空,請(qǐng)確保不會(huì)發(fā)生錯(cuò)誤$bookingIds。這是一種特殊情況,框架必須正確處理。)


查看完整回答
反對(duì) 回復(fù) 2023-07-21
  • 3 回答
  • 0 關(guān)注
  • 165 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)