<?php

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4;collation=utf8_general_ci;prefix=''", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$q = 1;

foreach($questions as $question) {

$stmt = $conn->prepare("SELECT * FROM tbl_questions WHERE id = :ques ORDER BY rand()");
$stmt->bindParam(':ques', $question);
$stmt->execute();
$result = $stmt->fetchAll();

foreach($result as $row)
{
$arr_m = [];
$qs = $row['question'];
$type = $row['type'];
$op1 = $row['op1'];
$op2 = $row['op2'];
$op3 = $row['op3'];
$op4 = $row['op4'];
$answer = $row['answer'];
array_push($arr_m, $op1, $op2, $op3, $op4);


?>

<div id="question-<?php echo $q?>" class="">
<?php echo $qs;?>
<?php
if ($type == "1") {

?>

<label class="radio radio-primary">
<input type="radio" name="answer<?php echo $q; ?>" value="op1">
<span>A) <?php echo $op1; ?></span>
<span class="checkmark"></span>
</label>

<label class="radio radio-primary">
<input type="radio" name="answer<?php echo $q; ?>" value="op2">
<span>B) <?php echo $op2; ?></span>
<span class="checkmark"></span>
</label>

<label class="radio radio-primary">
<input type="radio" name="answer<?php echo $q; ?>" value="op3">
<span>C) <?php echo $op3; ?></span>
<span class="checkmark"></span>
</label>

<label class="radio radio-primary">
<input type="radio" name="answer<?php echo $q; ?>" value="op4">
<span>D) <?php echo $op4; ?></span>
<span class="checkmark"></span>
</label>
<input type="radio" style="display:none !important;" name="answer<?php echo $q; ?>" value="N/A" checked="true">
<?php


}

if ($type == "2") {

?>
<div class="form-group">
<input name="answer<?php echo $q; ?>" autocomplete="OFF" type="text" class="form-control" value="">
</div>

<?php

}

?>

</div>

<?php


$q++;
}


}




}catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}


?>
