[請益] 請問一下資料庫執行兩次的問題?

看板PHP作者 (二老林)時間12年前 (2013/07/04 16:25), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
<?php mysql_connect("localhost","****","*******"); mysql_select_db("class"); if(!@mysql_select_db("class"))die("資料庫選擇失敗!"); $sql_query="select `total` from `total`"; $result=mysql_query($sql_query); while($row_result=mysql_fetch_assoc($result)){ $history=$row_result["total"]; $history=$history+$benefits; } echo $history; if(isset($_POST["action"])&&($_POST["action"]=="save")){ $sql_query="update `total` SET `total`=".$history; mysql_query($sql_query); header("location: stock.php"); } ?> 請問一下?我現在要做一個功能就是先從資料庫裡抓一個total的值出來然後再把benefit s的值加上去,然後再把加完的值$history存回到資料庫中,不知道這種情形要先關閉資 料庫然後再開,還是直接mysql_query就好? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 36.237.222.183

07/04 18:11, , 1F
不用重開
07/04 18:11, 1F
文章代碼(AID): #1HrJ5b-p (PHP)
文章代碼(AID): #1HrJ5b-p (PHP)