mercredi 4 mai 2016

Display the value of all checked checkboxes from mysql and display it in table

I designed the user registration page. It has one field hobbies. I designed the field with the help of checkbox. If the user selects two or more hobbies, i saved the hobby id in the database. Now i need to display the hobby names which are all selected by the particular user in their profile edit page. I done the below coding, but it displays the checkbox name from the database without selected. The checkbox name which is selected by the user should be checked. But it doesn't do that. Please provied any help.

<?php
$query = "SELECT * FROM hobbies";
$result = mysqli_query($con, "$query");
while ($r=mysqli_fetch_array($result)){
    $hobbyid=$r["hobby_id"];
    $hobbyname=$r["hobby_name"]; 
    if($hobby==$r[0]){ //Here $hobby is the hobby id which is entered by the user when registration. That hobby id is saved in the db.
        echo "<input type='checkbox' checked name='check_list[]' value='echo $hobbyid;'> $hobbyname";   
    }else{
        echo "<input type='checkbox' name='check_list[]' value='echo $hobbyid;'> $hobbyname";
    }
}
?>




Aucun commentaire:

Enregistrer un commentaire