how to retrieve data from databases into check boxes

i have stored the value of check box as 0 or 1
0 for off and 1 for on
plz tell me how to retrive that value again in checkboxes

hello mohsin1122,
suppose $result is an array containing complite detail of record and ‘chkboxval’ is filed in databsae table store checkbox value define as integer in tabele either 0 or 1.

<? if($result['chkboxval'] == 1)?>
<input type="checkbox" value="1" checked="checked" name="chkboxval" />
<? } else { ?>
<input type="checkbox" value="0" name="chkboxval" />
<? } ?>

SR

i got error in Integrating your code
plz help me
[php]
include(“includes/dbcon.php”);
$result = mysql_query(“SELECT * FROM payment methods order by PaymentMethodID ASC”);
$no_record = mysql_num_rows($result);
if($no_record > 0)
{
?>







<?php while($row = mysql_fetch_array($result)) { //$cc = $row['CreditCard']=='1'; // if($cc=='1'){echo "checked=\"checked\"";} echo '= '; } echo '
Payment ID Payment Method Credit Card Edit Delete
'.$row['PaymentMethodID'].' '.$row['PaymentMethod'].' '.[b]if($row['CreditCard']=='1'){""[/b]}.''.'Edit'.' '.'Delete'.'
'; } else { echo 'There is no record found'; } mysql_close($con); [/php] got error in above if statment help me

hello mohsin1122,

i have modify your code as per requirement. Try below code this will work for you.
[php]

<? include("includes/dbcon.php"); $result = mysql_query("SELECT * FROM `payment methods` order by PaymentMethodID ASC"); $no_record = mysql_num_rows($result); if($no_record > 0) { ?>
    <table width="90%" align="center" border="1">
      <tr>
        <th width="10%" bgcolor="orange">Payment ID</th>
        <th width="15%" bgcolor="orange">Payment Method</th>
        <th width="10%" bgcolor="orange">Credit Card</th>
        <th width="7%" bgcolor="orange">Edit</th>
        <th width="7%" bgcolor="orange">Delete</th>
<?php while($row = mysql_fetch_array($result)) { echo ' '.$row['PaymentMethodID'].' '.$row['PaymentMethod'].''; echo ''; if($row['CreditCard']=='1') { echo ''; } else { echo ''; } echo '' echo ''.'Edit'.' '.'Delete'.' '; } echo ''; } else { echo 'There is no record found'; } mysql_close($con); [/php] ~~SR~~

Thank You so much Mr.Sarthak Patel
u r genious

hello mohsin1122,
thanks and post more issues if you have. i am always here for your help.
Have a nice day!!! ;D :smiley:

SR

Sponsor our Newsletter | Privacy Policy | Terms of Service