我想使用mysql_fetch_array的结果更新mysql表中列的值
但最后的结果只是插入/更新到列
中的结果我错在哪里?这是我的代码。提前致谢
$studentname="some value";
$course="some value";
$query=mysql_query("select SABJEK,GRADE,REMARKS from table where STUDENTNAME='$studentname' && STUDENTNUMBER IS NULL") or die(mysql_error());
while($result=mysql_fetch_array($query))
{
$sabjek=$result['SABJEK'];
$grade=$result['GRADE'];
$remarks=$result['REMARKS'];
$msg="$sabjek = $grade - $remarks ";
$msg1="$studentname $course $msg";
}
mysql_query("update table2 set `msg`='$msg1' where studentname='$studentname'") or die(mysql_error());
答案 0 :(得分:1)
将mysql_query放入while中。基本上取代
}
mysql_query("update table2 set `msg`='$msg1' where studentname='$studentname'") or die(mysql_error());
与
mysql_query("update table2 set `msg`='$msg1' where studentname='$studentname'") or die(mysql_error());
}
它会起作用:)
答案 1 :(得分:0)
If you want to update the column name every-time whenvere you fetch the result just put update query inside the while loop,
$studentname="some value";
$course="some value";
$query=mysql_query("select SABJEK,GRADE,REMARKS from table where STUDENTNAME='$studentname' &&
STUDENTNUMBER IS NULL") or die(mysql_error());
while($result=mysql_fetch_array($query));
{ $sabjek=$result['SABJEK'];
$grade=$result['GRADE'];
$remarks=$result['REMARKS'];
$msg="$sabjek = $grade - $remarks ";
$msg1="$studentname $course $msg";
mysql_query("update table2 set `msg`='$msg1' where studentname='$studentname'") or
die(mysql_error());
}
如果你不期待这个结果,那么请详细解释我,我会更新答案。
感谢。