Mysql
 sql >> Base de données >  >> RDS >> Mysql

Cocher les cases des valeurs de la base de données

<?php
// Create connection
$con=mysqli_connect("hostname","username","pass","dbname");

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$result = mysqli_query($con,"SELECT focus FROM members_teachers WHERE id = $member_id"); 
while($row = mysqli_fetch_array($result))
  {
    $focus=explode(",",$row['focus']);

?>
<input type="checkbox" name="focus[]" value="Art" <?php if(in_array("Art",$focus)) { ?> checked="checked" <?php } ?> >
<input type="checkbox" name="focus[]" value="Mathematics" <?php if(in_array("Mathematics",$focus)) { ?> checked="checked" <?php } ?> >
<input type="checkbox" name="focus[]" value="Dance" <?php if(in_array("Dance",$focus)) { ?> checked="checked" <?php } ?> >
<?php
}
?>