Answer the question
In order to leave comments, you need to log in
How to make a linked list in Yii2 with the output of a row from the database?
<div class="row">
<div class="col-md-4 vcenter">
<?= $form->field($model, 'type_task_filter')->dropDownList(['city1'=>'city1','city2'=>city2'], ['prompt'=>'']); ?>
</div>
</div>
<div class="row">
<div class="col-md-4 vcenter">
<?= $form->field($model, 'type_task_filter')-> ? ?>
</div>
</div>
<select id="cityvm" onChange="change_city()">
<option></option>
<?php
$res=mysqli_query($link,"select * from cities");
while($row=mysqli_fetch_array($res))
{
?>
<option value="<?php echo $row["id"]; ?>"><?php echo $row["name"]; ?></option>
<?php
}
?>
</select>
Затем столбец для вывода строки из бд, которому задаем <div id="street">
function change_city()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "ajax.php?city="+document.getElementById("cityvm").value, false);
xmlhttp.send(null);
document.getElementById("street").innerHTML=xmlhttp.responseText;
}
if($city !=""){
$res = mysqli_query($link, "SELECT * FROM streets WHERE city_id = $city");
while ($row = mysqli_fetch_array($res))
{
echo "<option value='$row[id]' selected>";
echo $row["name"];
}
}
Answer the question
In order to leave comments, you need to log in
Ловим в js смену в select, отправляем ajax на сервер, там делаем выборку, возвращаем json (или готовый view), вставляем в DOM.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question