我厌倦了将数据更新到table_course
<?php
// update the ite_aps data into sgc table
require_once('../../includes/common.php');
$m = array();
$result = mysql_query("SELECT * from sgc where year = '2008'") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
//echo $row['nric'];
$res =mysql_query("select COURSE_TITLE_LONG, CRSE_GRADE_OFF, UNT_EARNED, nric from ite where nric = '".$row['nric']."' AND STRM = '2008'")or die(mysql_error());
$norows=mysql_num_rows($res);
echo $norows."<br>";
$update = 'UPDATE sgc SET meta_ite = ';
while($rows = mysql_fetch_array($res))
{
for($i=0;$i<$norows;$i++){
$data = array("course" => "'".$rows['COURSE_TITLE_LONG']."'" , "Grade" => "'".$rows['CRSE_GRADE_OFF']. "'" , "Unit" => "'".$rows['UNT_EARNED']."'");
$m = serialize($data);
}
print $m."<br>";
$update .= '"'.mysql_real_escape_string($m).'"';
}
$update .= 'WHERE nric = "'.$row['nric'].'" AND year = "2008"' ;
print $update."<br>";
// mysql_query($update);
}
&GT;
我得到以下输出以上编码
a:3:{s:6:"course";s:24:"'Personal Effectiveness'";s:5:"Grade";s:3:"'S'";s:4:"Unit";s:3:"'3'";}
a:3:{s:6:"course";s:16:"'Basic Numeracy'";s:5:"Grade";s:3:"'U'";s:4:"Unit";s:3:"'2'";}
a:3:{s:6:"course";s:23:"'Piping & Valve System'";s:5:"Grade";s:3:"'D'";s:4:"Unit";s:3:"'6'";}
a:3:{s:6:"course";s:24:"'Mechanical Fabrication'";s:5:"Grade";s:3:"'F'";s:4:"Unit";s:3:"'6'";}
输出格式为:array(course,grade,unit)array(course,grade,unit) - in serialize
但是,我想要这种格式的输出:array(array(course,grade,unit),array(course,grade,unit)........) -in serialize
例如:a:5:{a:3:{s:6:"course";s:24:"'Personal Effectiveness'";s:5:"Grade";s:3:"'S'";s:4:"Unit";s:3:"'3'";}'
a:3:{s:6:"course";s:16:"'Basic Numeracy'";s:5:"Grade";s:3:"'U'";s:4:"Unit";s:3:"'2'";}.......}
请任何人帮助我,因为我是php mysql的新手。
感谢。
答案 0 :(得分:0)
你正在接近这个问题。您不需要序列化任何内容。 我建议在php.net上阅读serialize()做什么以及它有用的地方。 要更新数据库,您只能发出1个查询。 由于这似乎是一个学校项目,我不会试图为你解决 - 上述提示应该有助于研究和自己得出结论:)