我的SQL表
table->requirement
id label_name label_value requirement_id
103 budget 5000 4
104 specialist dentist 4
105 treatment clinic 4
106 expertise criminal 5
107 charges 5100 5
我试图通过label_value
更新这个表中的mysql-php
。
我已经在php中尝试过这段代码,但它正在工作。
foreach ($data as $columnName => $colValue) {
echo $subQuery .= "UPDATE `$tableName` SET `label_value`='$colValue' where (`label_name`='$columnName' AND `requirement_id`='$id')";
mysql_query($subQuery);
}
得到输出-
更新
requirement
SETlabel_value
='Physician‘where (label_name
=’Physician‘和requirement_id
='2') 更新requirement
SETlabel_value
='Physician‘where (label_name
=’Physician‘和requirement_id
='2') 更新requirement
SETlabel_value
='On Your Home‘where (label_name
=’label_name
‘和requirement_id
='2')
我不知道这是不是正确,但我需要更新这个表格的形式。请帮我摆脱这一切。
发布于 2016-03-21 21:28:24
您需要从.
中删除.= "UPDATE
,因为它将连接您的查询。
对于循环的第一次发射,它将产生
UPDATE `$tableName` SET `label_value`='$colValue' where (`label_name`='$columnName' AND `requirement_id`='$id'
此查询工作正常,但对于第二次侦听,它将生成
UPDATE `$tableName` SET `label_value`='$colValue' where (`label_name`='$columnName' AND `requirement_id`='$id' UPDATE `$tableName` SET `label_value`='$colValue' where (`label_name`='$columnName' AND `requirement_id`='$id'
这是错误的语法。
只管用
foreach ($data as $columnName => $colValue) {
echo $subQuery = "UPDATE `$tableName` SET `label_value`='$colValue' where (`label_name`='$columnName' AND `requirement_id`='$id')";
mysql_query($subQuery);
}
尝试学习mysqli or pdo
,因为mysql被降级了
还可以学习查询
https://stackoverflow.com/questions/36129156
复制