我想要做的是在while循环中有一个单选按钮,每次循环运行时收音机的名称都会增加1.
现在代码无法正常工作,因为它没有逐步增加.任何建议都会很棒.
$query = mysql_query("SELECT * FROM table WHERE id = '1' ORDER BY time ASC");
echo '<table> <th> A </th> <th> time </th> <th> B </th>';
while($row = mysql_fetch_assoc($query)) {
$i= 1;
echo '<tr><td>';
echo '<input type="radio" name="';echo $i++; echo'" /> '; echo $row['a'];
echo '</td>';
echo '<td>';
echo $row['time'];
echo '</td>';
echo '<td>';
echo '<input type="radio" name="';echo $i++; echo '" />'; echo $row['b'];
echo '</td> </tr> ';
}
echo '</tr></table>';
Run Code Online (Sandbox Code Playgroud)
小智 7
你每次都要重置你的计数器.
$i = 1;
while($row = mysql_fetch_assoc($query)) {
// Your code
$i++;
}
Run Code Online (Sandbox Code Playgroud)
..并替换echo $i++;为echo $i;.