有人可以帮我修复此代码,以便选中的复选框将采用变量行号的值。我不关心它作为一个数组工作,直到我可以先得到这个基本的代码行。谢谢。
echo "<table>";
echo "<h2>FILMS : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "
<td width='20' align='center'>#</td>
<td width='20' align='center'>ID</td>
<td width='200' align='center'>TITLE</td>
<td width='200' align='center'>ROLE</td>
<td width='200' align='center'>DIRECTOR</td>";
echo "</tr>";
while ($row = mysql_fetch_array($result)) {
$id_actor= $row["id_actor"];
$idfilm= $row["idfilm"];
$filmTitle= $row["filmTitle"];
$filmRole= $row["filmRole"];
$filmDirector= $row["filmDirector"];
//Here's the Problem
echo"<tr>";
echo '<td><input name="checkbox[]"
value="id_actor" //POST a value that equals a variable row selected?
type="checkbox"
id="checkbox[]" /></td>';
for ($i=0; $i<5; $i++)
{
echo"<td> $row[$i]</td>";
}
echo"</tr>";
}
echo"</table>";
答案 0 :(得分:1)
您可以使用以下代码替换您的作品
$row_number = 1;
while ($row = mysql_fetch_array($result)) {
$id_actor= $row["id_actor"];
$idfilm= $row["idfilm"];
$filmTitle= $row["filmTitle"];
$filmRole= $row["filmRole"];
$filmDirector= $row["filmDirector"];
//Here's the Problem
echo"<tr>";
echo '<td><input name="checkbox[]" value="id_actor'.$row_number.'" type="checkbox"
id="checkbox'.$row_number.'" /></td>';
for ($i=0; $i<5; $i++) {
echo"<td> $row[$i]</td>";
}
echo"</tr>";
$row_number++;
}
答案 1 :(得分:0)
我不确定这是否是你想要完成的事情,但不管怎么说。
echo "<table>";
echo "<h2>FILMS : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "
<td width='20' align='center'>#</td>
<td width='20' align='center'>ID</td>
<td width='200' align='center'>TITLE</td>
<td width='200' align='center'>ROLE</td>
<td width='200' align='center'>DIRECTOR</td>";
echo "</tr>";
while ($row = mysql_fetch_array($result)) {
$id_actor= $row["id_actor"];
$idfilm= $row["idfilm"];
$filmTitle= $row["filmTitle"];
$filmRole= $row["filmRole"];
$filmDirector= $row["filmDirector"];
//Here's the Problem
echo '<tr>';
echo '<td><input name="checkbox[]" id="checkbox[]" type="checkbox" value="'.$id_actor.'" /></td>';
echo '<td><input name="checkbox[]" id="checkbox[]" type="checkbox" value="'.$idfilm.'" /></td>';
echo '<td><input name="checkbox[]" id="checkbox[]" type="checkbox" value="'.$filmTitle.'" /></td>';
echo '<td><input name="checkbox[]" id="checkbox[]" type="checkbox" value="'.$filmRole.'" /></td>';
echo '<td><input name="checkbox[]" id="checkbox[]" type="checkbox" value="'.$filmDirector.'" /></td>';
echo '</tr>';
}
echo"</table>";