php / mysql通过循环更新行

时间:2014-01-09 02:29:29

标签: php mysql sql

我正在尝试运行这个PHP脚本....现在阵列有3行,3个不同的学校同一个人/数字。当我发布/提交更新的信息时,它只发布第1行和第3行,第1行发布值。它不会更改第2行的值。我的问题..是否有任何红旗突出?如果这是脚本,为什么只更新某些行而不是所有行?我需要一个能在循环中执行它的时间吗?

<?php
for ($i=0; $i<count($_POST['row']); $i++){
$number = 223;
$row = $i+1;
$school = mysqli_real_escape_string($con, $_POST['school'][$i]);  

$query = " set @type = '';";
$query .= " set @num = 1;";
$query .= " update person set person.school = '$school' where person.id in (";
$query .= "select t.id from (";
$query .= "select *, @num:= if(@type = number, @num + 1, 1)  as num, @type := number as Dummy from person    order by it desc) as t where t.number = '$id' and num = '$row');";
mysqli_multi_query($con, $sql);
?> 

这是我运行php时得到的。我打破了它,你可以看到。

set @type = ''; 
set @num = 1; 
update person set person.school = 'Harvard1' where person.id in (select t.id from (select *, @num:= if(@type = number, @num + 1, 1) as num, @type := number as Dummy from person order by it desc) as t where t.number = '223' and num = '1'); 

set @type = ''; 
set @num = 1; 
update person set person.school = 'Harvard2' where person.id in (select t.id from (select *, @num:= if(@type = number, @num + 1, 1) as num, @type := number as Dummy from person order by it desc) as t where t.number = '223' and num = '2'); 

set @type = ''; 
set @num = 1; 
update person set person.school = 'Harvard3' where person.id in (select t.id from (select *, @num:= if(@type = number, @num + 1, 1) as num, @type := number as Dummy from person order by it desc) as t where t.number = '223' and num = '3'); 

0 个答案:

没有答案