I want to create a form using a table where a column generates the questions( nom ) and another one generates the type of the response(type ) that can be (text, date, checkbox, radio etc ...), I was able to generate the questions however I wasn't able to determinate the type.
I am really struggling to use the type column in my champs table as a variable of input types in a form.
Any help would be extremely appreciated
to clarify more here are my codes:
ChampsModel.php
<?php
require_once("../config/database.php");
function Champsbyqid($qid){
$c = Database :: connect();
$results = array();
$q = $c -> prepare ("SELECT nom FROM champs WHERE qid=?") ;
$q -> execute (array($qid));
while ($data = $q -> fetch()) {
$results[] = $data;
}
Database :: disconnect();
return $results;
}
function getType($qid){
$c = Database :: connect();
$results = array();
$q = $c -> prepare ("SELECT type FROM champs WHERE qid=?") ;
$q -> execute (array($qid));
while ($data = $q -> fetch()) {
$results[] = $data;
}
Database :: disconnect();
return $results;
}
?>
ChampsController.php
<?php
require_once("../model/champsModel.php");
$champs = Champsbyqid(1);
$type = getType(1);
?>
Champs.php
<?php
require_once("../controller/champsController.php");
foreach ($champs as $value) {
foreach ($types as $val) {
echo $value['nom'].'<form method="POST"><input type='$val['type']'></form>';
}
}
?>
?>