Hi, I'm doing a dynamic selection with php and mysql I found an example but it was not in mvc so I tried to change some things like the address where my controller is but it stays in a loop and does not show me anything in the select
Este es mi modelo
<?php
class Trat
{
public function selectNombre ()
{
try {
include('../model/conexion.php');
$rows = null;
$stmt = $dbh->prepare("SELECT * FROM n_tratamiento");
$stmt->execute();
while ($result = $stmt->fetch()) {
$rows[] = $result;
}
return $rows;
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
}
public function selectDescripcion ()
{
try {
include('../model/conexion.php');
$rows = null;
$stmt = $dbh->prepare("SELECT * FROM d_tratamiento where id_descripcion=$nombre_t");
$stmt->execute();
while ($result = $stmt->fetch()) {
$rows[] = $result;
}
return $rows;
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
}
}
?>
My sight
</head>
<body class="">
<div class="container" >
<h1>ACEPTACION DE TRATAMIENTOS Y PRESUPUESTOS DE PACIENTE</h1>
<select class="form-control" id="continentes"required="required" name="txtN_tratamiento">
<option value="">--Seleccione--</option>
<?php Select();?>
</select>
<select class="form-control" id="paises" required="required" name="txtD_tratamiento">
<option value="">--Seleccione--</option>
<?php Select2();?>
</select>
and my driver
function Select(){
$consultas=new Trat();
$filas=$consultas ->selectNombre();
foreach($filas as $fila){
echo "<option value=".$fila['id'].">".$fila['tratamiento']."</option>";
}
}
function Select2(){
$consultas=new Trat();
$nombre_t = $_POST['txtN_tratamiento'];
$filas=$consultas ->selectDescripcion();
foreach($filas as $fila){
echo "<option value=".$fila['id_descripcion'].">".$fila['descripcion']."</option>";
}
}
this is the javascript that should work
$(function(){
// Lista de Continentes
$.post( '../controller/c_presupuesto.php/' ).done( function(respuesta)
{
$( '#continentes' ).html( respuesta );
});
// lista de Paises
$('#continentes').change(function()
{
var el_continente = $(this).val();
// Lista de Paises
$.post( 'c_presupuesto.php/select()2', { continente: el_continente} ).done( function( respuesta )
{
$( '#paises' ).html( respuesta );
});
});
// Lista de Ciudades
$( '#paises' ).change( function()
{
var pais = $(this).children('option:selected').html();
alert( 'Lista de Ciudades de ' + pais );
});
})