有人可以帮我修复此代码,以便选中的复选框将采用变量行号的值。在我首先获得这行基本代码之前,我不关心它作为数组工作。谢谢。
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>";
你可以用以下代码替换你的创作
$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++;
}
我不确定这是否是您想要完成的,但它就在这里。
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>";