i'm a php nearby. I have a problem with my form. I connect the controller with db and extract a question and his three answers. If i click on one of this, the system return the second question, under the first question. If i click on one of the seconds answers, the system return the thirth question overwrite the second question. I would like that second question (and its answers) overwrite the first (and its answers). How i can? db structure view
1) index.php
<?php
error_reporting(E_ERROR | E_PARSE);
require_once 'controllers/controller.php';
$controllers = new Controller();
$controllers->cercaDomanda(1);
$controllers->cercaRisposta(1);
$controllers->cercaNuovoId($id);
?>
2) Controller.php
<?php
require_once('models/Domanda.php');
require_once('models/Risposta.php');
require_once ('models/Model.php');
class Controller {
public $domanda;
public $risposta;
public $model;
public function __construct(){
$this->domande = new Domanda(); //istanziamo la classe domanda
$this->risposte = new Risposta(); //istanziamo la classe risposta
$this->model = new Model(); //istanziamo la classe risposta
}
public function cercaDomanda($id){
$reslt = $this->domande->getDomanda($id);
include 'views/basicView.php';
}
public function cercaRisposta($id){
$reslt2 = $this->risposte->getRisposta($id);
include 'views/basicView.php';
}
public function cercaNuovoId($id){
include 'views/basicView.php';
$reslt3 = $this->model->getIdNext();
$reslt4 = $this->cercaDomanda($reslt3);
$reslt5 = $this->cercaRisposta($reslt3);
}
}
?>
3)Domanda.php
<?php
require_once 'models/Domanda.php';
class Domanda {
public function getDomanda($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT domanda FROM public."Domande" WHERE "id"='.$id;
$result = pg_query($query);
return $result;
pg_close($dbconnection);
}
}
?>
4)Risposta.php
<?php
require_once 'models/Risposta.php';
class Risposta {
public function getRisposta($id){
$dbconnection = pg_connect("host=***port=***dbname=***user=***password=***");
$query = 'SELECT * FROM public."Risposte" WHERE "id_domanda"='.$id;
$result = pg_query($query); //or die ('Query fallita: ' .pg_last_error());
return $result;
pg_close($dbconnection);
}
}
?>
5)Model.php
<?php
require_once 'models/Model.php';
class Model {
public function getIdNext(){
if(isset($_POST['btnScelta'])){
$result = $_POST['btnScelta'];
return $result;
}
}
}
6)View
<html>
<head></head>
<body>
<form action='index.php' name='chatbotyForm' method="POST">
<table>
<?php
echo "<tr>";
$domanda = pg_fetch_array($reslt, null, PGSQL_ASSOC);
print $domanda['domanda'];
echo "</tr>";
?>
</table>
<?php
while ($rispost = pg_fetch_object($reslt2)) {
print "<td><button type='submit' name='btnScelta'
value='$rispost->id_domanda_successiva'>$rispost->risposta</button>
</td>";
}
?>
</form>
</body>
</html>