更新具有相同行但不同单元名称的mysql表
问题描述:
how i can update mysql table with php?
example
i have:
$sql = mysql_query("UPDATE table_name SET numbers = 'null' where no = '1'") or die(mysql_error());
$sql = mysql_query("UPDATE table_name SET numbers = 'null' where no = '2'") or die(mysql_error());
$sql = mysql_query("UPDATE table_name SET numbers = 'null' where no = '3'") or die(mysql_error());
i need one mysql request, i try this example but it doesn't work.
$sql = mysql_query("UPDATE table_name SET numbers = 'null' WHERE no IN ('1, 2, 3')") or die(mysql_error());
我如何用php更新mysql表? p>
示例 p >
我有: p>
$ sql = mysql_query(“UPDATE table_name SET numbers ='null',其中no ='1'”)或死亡( mysql_error());
$ sql = mysql_query(“UPDATE table_name SET numbers ='null',其中no ='2'”)或die(mysql_error());
$ sql = mysql_query(“UPDATE table_name SET numbers = 'null',其中no ='3'“)或死(mysql_error());
code> pre>
我需要一个mysql请求,我试试这个例子,但它没有' 工作。 p>
$ sql = mysql_query(“UPDATE table_name SET numbers ='null'WHERE IN IN('1,2,3')”)或die(mysql_error( ));
code> pre>
div>
答
If you remove the single quotes around your WHERE no IN ('1, 2, 3')
it will fix your problem
This is assuming that your no column is an integer column
答
The solution you have come up with only has one item in the IN
, and so would be equivalent to:
UPDATE table_name SET numbers = 'null' WHERE no = '1, 2, 3'
You need to use separate strings for each value, i.e.:
UPDATE table_name SET numbers = 'null' WHERE no IN ('1', '2', '3')