$a = mysql_query('SELECT cc.name, c.fullname,c.shortname FROM course c, category cc
WHERE cc.id = c.categoryid');
echo '<form action="" method="post">';
echo '<center><div style="margin-top:40px;"><input type="submit" name="submit" value="PUBLISH"></div></center>';
echo '<table border="1" width="100%" style="border:1px solid lightgray;">
<tr style="color:#808080;">
<th>CategoryName</th>
<th>Course Fullname</th>
<th>Course Shortname</th>
<th>Total</th>
</tr>';
while ($row = mysql_fetch_assoc($a))
{
$categoryname = $row['name'];
$coursename = $row['fullname'];
$shortname = $row['shortname'];
echo '<tr><td>'.$categoryname.'</td>
<td>'.$coursename.'</td>
<td>'.$shortname.'</td>
<td style="padding:17px;"><center><input type="text" size="4%" name="grade"></center></td></tr>';
if($_SERVER['REQUEST_METHOD']=='POST')
{
$total = $_REQUEST["grade"];
$sql="INSERT INTO course_custom(category,fullname,shortname,total) VALUES('$categoryname', '$coursename', '$shortname','$total')";
$result=mysql_query($sql);
}
}
echo '</table>';
echo '</form>';
Rightnow我能够使用上面的代码正确插入category,coursename和shortname,但是总列的所有行都会重复使用。
是否有人建议将每行的正确值插入数据库