sql - Checkboxes with PHP & SQLExpress Server 2008 -


i have local application reads data local sql server, works select queries , outputting text in table i'm having difficulty outputting checkbox status either checked or unchecked :(

see code:

<?php     while( $row2 = sqlsrv_fetch_array( $stmt2, sqlsrv_fetch_assoc) ) {         echo "<tr>";         echo "<td>" . "<input class=form-control id=input-readonly type=text name=supcode value=" . $row2['column1'] . " readonly></td>";         echo "<td><input type=checkbox" .          if ($row2['checkbox_column1'] ==1)              echo "checked='checked'>" . "</td>";         echo "</tr>";     }      sqlsrv_free_stmt( $stmt2); ?> 

the checkbox_column1 column bit datatype

any guidance appreciated, thank you!

you aren't closing input if checkbox column empty. concatation noted won't work if.

try updating to:

 $checked = $row2['checkbox_column1'] == 1 ? " checked='checked'" : '';    echo "<td><input type='checkbox'$checked></td>";   echo "</tr>"; 

demo: http://3v4l.org/hoojq

if column == 1 output be:

<td><input type='checkbox' checked='checked'></td></tr> 

else

<td><input type='checkbox'></td></tr> 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -