Hi friends!!
I have a problem, and can’t solve.
I have the an dependent select , but loading the file with the second dropdownlist, this not show the result of the query.
Below is the code and explanation:
This file load the first dropdownlist whitout problems:
//file: a.php
function idpadre($valor)
{
$SQL=(focos());
$connection=Yii::$app->db;
$command=$connection->createCommand($SQL);
$rowCount=$command->execute();
$dataReader=$command->query();
echo "<select class='select' name='idpadre' id='idpadre'>";
echo "<option value=''>Seleccione Foco Estratègico ...</option>";
foreach($dataReader as $row)
{
echo "<option value='".$row["id_foco_estrategico"]."'";
if ($row["id_foco_estrategico"]==$valor) echo 'selected';
echo ">".utf8_encode($row["descripcion_foco"])."</option>\r\n";
}
echo "</select>";
}
Ajax is called, forwards parameters "idpadre" and "buscar" , and load whitout problems the b.php file:
//file: script.js
$(document).ready(function() {
$("#idpadre").change(function(event)
{
var idpadre = $(this).find(':selected').val();
//$("#pidhijo").html("<div><img src='/basic/web/images/loading.gif' /></div>");
$("#pidhijo").load("/basic/views/superadmin/b.php?buscar=hijos&idpadre="+idpadre);
var idhijo = $("#idhijo").find(':selected').val();
//$("#pidnieto").html("<img src='/basic/web/images/loading.gif' />");
$("#pidnieto").load('../../views/superadmin/b.php?buscar=nietos&idhijo='+idhijo);
var idnieto = $("#idnieto").find(':selected').val();
//$("#pidbisnieto").html("<img src='/basic/web/images/loading.gif' />");
$("#pidbisnieto").load('../../views/superadmin/b.php?buscar=bisnietos&idnieto='+idnieto);
});
}
the problem is here. no load $connection or the query … i don’t understand
//file: b.php
if ($_GET['buscar']=="hijos")
{
$a=mysql_real_escape_string(intval($_GET['idpadre']));
$SQL=(unidades($a));
/* desde aqui el problem
$connection=Yii::$app->db;
$command=$connection->createCommand($SQL);
$rowCount=$command->execute();
$dataReader=$command->query();
echo "<label>Unidad a:</label><select class='select' name='idnieto' id='idnieto'>";
echo "<option value=''>Seleccione opcion...</option>";
foreach($dataReader as $row)
{
echo "<option value='".$row["id_unidad"]."'";
if ($row["id_unidad"]==$valoractual) echo 'selected';
echo ">".utf8_encode($row["unidad"])."</option>\r\n";
}
echo "</select>";
}
Than you for help me
Regards!!