php批量更新數(shù)據(jù)源碼 php更新數(shù)據(jù)庫字段

Thinkphp怎么批量更新數(shù)據(jù)

thinkphp里面其實跟原生語句沒有什么區(qū)別,你可以用where限定更新條件,再save($data)中將你要更新的數(shù)據(jù)存在data里面。這樣是你要把數(shù)據(jù)更新成一樣的時候。如果更新的字段及值不一樣的話,據(jù)我所知就只能一條條的循環(huán)更新了。

創(chuàng)新互聯(lián)公司是一家成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),提供網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,網(wǎng)站制作,建網(wǎng)站,定制網(wǎng)站開發(fā),網(wǎng)站開發(fā)公司,于2013年創(chuàng)立是互聯(lián)行業(yè)建設(shè)者,服務(wù)者。以提升客戶品牌價值為核心業(yè)務(wù),全程參與項目的網(wǎng)站策劃設(shè)計制作,前端開發(fā),后臺程序制作以及后期項目運營并提出專業(yè)建議和思路。

php如何用update更新多條數(shù)據(jù)

樓主貼出的代碼是主要代碼不是完整代碼,以下是對你貼出代碼的修改,接收數(shù)組并批量更新

接收數(shù)據(jù)格式形如:

array(

0=array(

'id' = 1,

'title'= '標(biāo)題1'

'url'= '...'

),

1=array(

'id' = 1,

'title'= '標(biāo)題1'

'url'= '...'

),

)

注意在原來的基礎(chǔ)上加了更新條件id,不加的話是會更新全部的。

A頁面代碼:

?php

$exec="select * from focusimg";

$result = mysql_query($exec,$link);

$i=0;

while($pt=mysql_fetch_array($result)){

?

tr onmouseover="this.className='admTr'" onmouseout="this.className=''"

td width="17%" align="right"標(biāo)題?php echo $pt['id']; ?:input name="?php echo "focusimg[$i][id]"; ?" value="?php echo $pt['id']; ?" type="hidden"http://td

tdinput name="?php echo "focusimg[$i][title]"; ?" type="text" id="textfield" value="?php echo $pt['title'];?" size="30" //td

td width="17%" align="right"鏈接?php echo $pt['id']; ?:/td

tdinput name="?php echo "focusimg[$i][url]"; ?" type="text" id="textfield" value="?php echo $pt['url'];?" size="30" / /td

/tr

?php

$i++;

};

?

B頁面代碼:

?php

include 'conn.php';

$focusimg=$_POST['focusimg'];

foreach($focusimg as $k=$v) {

$exec="update chips set title='{$v[title]}',url='{$v[url]}' where id='{$v[id]}'";

mysql_query($exec, $link);

}

mysql_close($link);

echo "edit OK!";

?

PHP如何批量更新數(shù)據(jù)?急?。?!

更新是要更新兩次 但是你可以用循環(huán)批量更新的!

對數(shù)據(jù)庫的操作是每次一條 或者 你可以寫事務(wù)的,這樣的話就比較麻煩了

就用循環(huán)吧

首先把你的一個tr/tr中的四個內(nèi)容都用相應(yīng)的數(shù)組名字name[]作名字

然后 提交后 得出來數(shù)組長度 然后循環(huán)相應(yīng)的次數(shù)

執(zhí)行SQL操作 就OK

如果具體的 問題 可以 留言

新聞名稱:php批量更新數(shù)據(jù)源碼 php更新數(shù)據(jù)庫字段
地址分享:http://bm7419.com/article10/ddepsdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、移動網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、Google、小程序開發(fā)定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)