如何做到多筆資料的同步

一次叫出多筆資料,然後在同一個網頁中「逐一」「分別」做不同的處理,最後「同時」對資料庫 update or insert 。每一筆資料所收到的update 、insert數據並不相同! ============================
處理要點在於 _____ loop + array

1.從資料庫叫出資料:
db_query進行looping的同時,把相關欄位需要update的資料通通納入array.
依照各人需求,這些資料可以用text、checkbox、或者hidden等各種型態呈現。當然,checkbox是最常見的type.
例如,郵件處理網頁就大量使用checkbox.
2.修改後的資料回存作業
要點在count(array) + loop + db_update:
根據count的結果進行迴旋,把db_update放進去,讓loop去完成所有資料的update回存作業。
範例如下:

####1.update.php: 以loop+array取出資料以便update........

 1<form action="activate.php">   
 2#在這裡呼叫資料庫   
 3$query="select * from $userstable where...................   
 4  
 5#進入loop逐一取出資料   
 6$i=0;   
 7while ($i &lt; $num):   
 8...............   
 9$id=mysql_result($result,$i,"id");   
10..................   
11............................   
12#以適當的type取出必須更新的欄位,構成array ..........   
13echo "<td "<td="" align="middle" align...................="" echo=""><input name='\"Cname[]\"' size="3" type="text" value='\"$name\"'/></td>";   
14echo "<input name='\"Cid[]\"' type="hidden" value='\"$id\"'/>";   
15  
16$i++;   
17endwhile;   
18  
19  
20======================================================   
21####2.activate.php:資料更新後,透過loop+array完成回存...................   
22  
23.......   
24for ($i = 0; $i &lt; count($Cname); $i++) {   
25$name = $Cname[$i];   
26$id= $Cid[$i];   
27  
28$query = "update $userstable set name='$name' where id='$id'";   
29.............</form>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus