我想根据以前的查询结果更新数据。
我的第一个查询返回GRN编号,我想同时更新这些GRN编号到另一个表中。
这是我的代码:
$sqlsel = "SELECT `grn` FROM `tblstudent` WHERE `classname` = '$class' AND `division` = '$division'";
$queryselgrn = mysql_query($sqlsel);
while($row = mysql_fetch_array($queryselgrn)) {
$grn = array();
//$grn = $row["grn"];
$grn = $row['grn'];
}
$grn = explode("-",$grn);
$j = 1;
foreach($grn as $v) {
$j = $v;
echo $j;
$sqlup = "UPDATE `tblhomeworkstatus` SET `studentid`='$j' WHERE `hwid` ='$hwid'";
$j++;
$queryup = mysql_query($sqlup);
}
if(!$query and !$queryins) {
die('not inserted:' .mysql_error());
} else {
echo "inserted!";
}