Reputation: 243
I'm working on a php/mysql page. 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. 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>" );
}
Upvotes: 0
Views: 320
Reputation: 196
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>";
}
Upvotes: 1