我有一个包含数据
的表格| id | player | runs |
|-----|---------|-------|
| 1 | A | 3000 |
| 2 | B | 1000 |
| 3 | C | 5000 |
这是一个大数据集的摘要,来自json格式的web服务,我必须使用PHP更新所有行的新数据,为了测试我试图更新所有玩家和SET 3000的运行
foreach($json as $indx=>$val)
{
$upd_qry = "UPDATE info SET runs = 3000 WHERE player='$indx'";//Here on each iteration I'm getting current player and Updating its runs
$exec_qry = mysqli_query($con,$upd_qry);
if ($exec_qry) {
echo $indx.":".$val;
}
}
此查询未更新,请解决此问题
答案 0 :(得分:0)
您的查询必须是:
$upd_qry = "UPDATE info SET runs = 3000 WHERE id='$indx'";
答案 1 :(得分:0)
foreach($json as $indx=>$val)
{
$upd_qry = "UPDATE info SET runs = 3000 WHERE player='".$indx."'";//Here on each iteration I'm getting current player and Updating its runs
$exec_qry = mysqli_query($con,$upd_qry);
if ($exec_qry) {
echo $indx.":".$val;
}
}
答案 2 :(得分:0)
查询应该是这样的:
$upd_qry = "UPDATE info SET runs = 3000 WHERE player=$indx ";
&#39>'和""。单引号表示为字符串,您还必须回显查询,因此您可以检查差异。