Jump to content

[SOLVED] populate checkbox from mysql


brem13

Recommended Posts

i have a page where i am displaying text in textboxes from a mysql database and i also want to populate the checkboxes if there is a field in the database that reads 'Yes', and i cant figure out how to check the checkbox if featured = Yes?? any suggestions please??

 

$feat = $qry['featured'];

if($feat == "Yes")

$value= "checked";

else

$value = "";

 

    echo '<input type=hidden name=pic['.$counter.'] value='.$pic.'><input type=text name=comment['.$counter.'] value="'.$qry['comment'].'">Featured:<input type=checkbox name=featured['.$counter.'] value='.$value.'></td>';

Link to comment
https://forums.phpfreaks.com/topic/148481-solved-populate-checkbox-from-mysql/
Share on other sites

//Shorthand if/else to set the value of $checked to
// checked="checked" or empty string
$checked = ($feat == "Yes") ? ' checked="checked"' : '';

echo "<input type=\"hidden\" name=\"pic[{$counter}]\" value=\"{$pic}\" />
      <input type=\"text\" name=\"comment[{$counter}]\" value="{$qry['comment']}\" />
      Featured:<input type=\"checkbox\" name=\"featured[{$counter}]\" value=\"Yes\"$checked /></td>"; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.