mardi 18 juillet 2017

Select the check box based on db values

I have two tables.Have to list the values from one table as check box and check the check boxes based on values from another table. Here is my code..

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "employee";


$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$fetch = "SELECT * FROM emp_type where emp_id=1";
$result_fetch = mysqli_query($conn, $fetch);
$selected_result=array();
if (mysqli_num_rows($result_fetch) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result_fetch)) {
       array_push($selected_result,$row['type_name']);
    }
} else {
    echo "0 results";
}
echo json_encode($selected_result);
$sql = "SELECT * FROM type_master";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo '<input type=checkbox name=$row[type_name] value=$row[type_name]>'.$row['type_name'];
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>

I tried in_array but its not working




Aucun commentaire:

Enregistrer un commentaire