php while循环与$ i ++ - php

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center。

7年前关闭。

我想要做的是在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>';

参考方案

您每次都要重置计数器。

$i = 1;

while($row = mysql_fetch_assoc($query)) {
    // Your code

    $i++;
}

..并将echo $i++;替换为echo $i;

AJAX + PHP +下载mPDF生成的文件 - php

我正在创建一个应用程序,用户可以访问查看表中显示的许多PDF。每行还具有复选框,允许用户检查或不检查我稍后将描述的下一个动作。这些复选框位于表单标记内,然后是一个提交按钮,该按钮通过POST方法通过AJAX REQUEST将数组内的所有文件ID发送到PHP文件。AJAX请求如下所示:$.ajax({ url: link, type: 'POST&#…

相对+基本URL到绝对URL? - php

基本上,给定基本网址,例如file:///path/to/some/file.html 还有一个相对URLanother_file.php?id=5 我要出去file:///path/to/some/another_file.php?id=5 我找到了this script(与this one相同),但是在file://方案上似乎不起作用。在使用代码之前,我…

在Java中,执行“ ++++++++”表达式,编译器未报告任何错误并且可以正确执行? - java

我用eclipse编写了这段代码,用war写过,结果为3d。public static void main(String[] args) { double a = 5d + + + + + +-+3d; System.out.println(a); } 参考方案 您的表情可以改写为(5d) + (+ + + + +-+3d) 其中第一个+是应用于两个操作数的…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…