简体   繁体   English

php checkbox id = mysql id

[英]php checkbox id = the mysql id

I'm working on a php/mysql page. 我正在php / mysql页面上工作。 I have the table displaying the results I want with a checkbox in front of each row, and I'm having difficulty labeling the id/name of the checkbox the row id from the query that I've done. 我的表在每行的前面都有一个复选框,以显示我想要的结果,而我在将复选框的ID /名称标记为我完成的查询的行ID时遇到了困难。 I have tried looking at this, and have seen several examples that it's possible but wasn't able to see the code. 我尝试着看这个,并看到了几个可能的例子,但看不到代码。 Any help would be appreciated. 任何帮助,将不胜感激。 I have this code: 我有以下代码:

    for ( $counter = 0; $row = mysql_fetch_row( $result );$counter++ ){

           // build table to display results

           print( "<tr>" ); 

           print("<td> <input type='checkbox' name='$row['id']' value='". $row['id'] ."'> </td>");

           foreach ( $row as $key => $value ) 
              print( "<td>$value</td>" );

           print( "</tr>" );
        }

There a lot of things wrong. 有很多错误的地方。

Look the "for" structure. 寻找“为”结构。

The correct is: 正确的是:

for($conter = 0; $counter < count(mysql_fetch_row( $result ); $counter++)
...

Or you can use this: 或者您可以使用以下命令:

foreach(mysql_fetch_row($result) as $row){
    echo "<td><input type='checkbox' name='$row['id']' value='$row['id']'></td>";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM