作者Relent (遺憾)
看板PHP
標題[請益] update 資料問題
時間Thu Jul 14 15:22:16 2016
我在php中做更新紀錄的動作
根據print出來的sql語法如下
update `tableS` set `history`='[{"time":"2016-07-14
18:24:22","count":0,"link":"
http://aaa.bbb.cc"}]' where account='110101'
只是我的資料表history欄位裡面的資料,卻變成了這樣
[{"time":"2016-07-14
18:24:22","count":0,"link":"
http://aaa.bbb.cc"},
{"time":"2016-07-14
18:24:22","count":0,"link":"
http://aaa.bbb.cc"},
{"time":"2016-07-14
18:24:22","count":0,"link":"
http://aaa.bbb.cc"},
{"time":"2016-07-14
18:24:22","count":0,"link":"
http://aaa.bbb.cc"}]
多出了3筆同樣的紀錄
想請問一下各位大大這種狀況是因為什麼呢
程式碼如下,
[code]
$count=0;
$bitStr="1101010101111010";
while($count<30 && strlen($bitStr)>0){
$percent=0.1;
$obj=new stdClass();
$obj->time=$checkDate;
$obj->count=$count*$percent;
$obj->link=$url;
$arr=array();
array_push($arr,$obj);
$str=json_encode($arr);
$sql="update tableS set history='".$str."' where account='".$bitStr."'";
echo $sql;
mysql_query($sql);
$count++;
$bitStr=substr($bitStr,0,-1);
}
[/code]
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 124.9.192.236
※ 文章網址: https://webptt.com/m.aspx?n=bbs/PHP/M.1468480944.A.7A6.html
1F:推 ns1234: escape? 07/14 16:35
2F:→ shadowjohn: 完了…等一下會有二個大師兄上來唸你 07/14 20:57
3F:→ Relent: 呃 請問S大是有看出哪裡不妥嗎 是我程式的寫法不好嗎 07/15 01:49
4F:→ Relent: 這個問題我試了一天,發現用IE不會出現這樣的狀況,chrome 07/15 01:50
5F:→ Relent: 會,應該要如何避免呢? 07/15 01:51
6F:推 wilson200106: 先試試unset掉看看.......? 07/15 09:52
7F:→ gname: 你要不要reset chrome一下,我跑沒問題啊... 07/15 09:58
8F:推 locklose: PDO表示: 07/15 11:55
9F:推 shadowjohn: 先不管瀏覽器…這樣切切切處理的用意是什麼呢? 07/15 13:27
10F:→ Relent: 呃 那個是本來資料庫的規劃,一個二元樹的編號,一層層的 07/19 19:15
11F:→ Relent: 往上找 07/19 19:15