简体   繁体   English

如何使用MySQL PHP动态基于下拉更改更改div内容

[英]how to change div contents based on drop down change dynamically using mysql php

how to change div contents based on dropdown change dynamically using mysql php ? 如何使用MySQL php动态基于下拉列表更改div内容?

$sql = mysqli_query($conn,"SELECT vendor_info.`vender_id`, vendor_info.`vender_name` , products.`vender_id` , products.`prod_id` , products.`prod_name` FROM vendor_info,products WHERE vendor_info.`vender_id` =products.`vender_id`");

                                                while ($row = mysqli_fetch_array($sql))
                                                 { 
                                                echo  $v_id=mysqli_real_escape_string($conn,$row['vender_id']);
                                                  $sql_b=mysqli_query($conn,"select * from `vendor_info` where `vender_id`= '$v_id'");
                                                ?>
                                                  <option value="<?php echo $v_id ?>"><?php echo $row['vender_name'];?></option>
                                             <?php  
                                               }
                                               ?>

                                             </select>
                                          </div>

                                         </div>


                            </div>

                            <hr>

                            <div class="row">
                                <div class="col-sm-6">
                                            <?php 
                                            echo $que ="select * from products where vender_id='$v_id'";
                                                   $query=mysqli_query($conn,$que);
                                                   while($result=mysqli_fetch_array($query)){
                                             ?>

                                     <div class="<?php echo $v_id ?> box">You have selected <strong><?php echo $row['prod_name']; ?></strong> so i am here
                                           <?php }?>
                                    </div>

in second div i want to change content based on drop down selection. 在第二个div中,我想基于下拉选择更改内容。 i put code in second div for fetching data according to id of select box. 我把代码放在第二个div中,以便根据选择框的ID来获取数据。 but this code not work. 但是此代码不起作用。

You an load the content of the second div using AJAX. 您使用AJAX加载第二个div的内容。 In your first div make onchange call to a function Eg: <select onchange='loadDiv(this.value);'> This will call a function loadDiv(value) , there you can send a ajax request to a file which will fetch the data based on the value of the First select box. 在您的第一个div中,对函数进行onchange调用,例如: <select onchange='loadDiv(this.value);'>这将调用函数loadDiv(value) ,您可以在其中发送ajax请求到文件,该文件将获取数据基于“第一次选择”框的值。 Then you can simply load the content using CSS selector $('#secondDiv).html(result) Here the result is the drop down content which is returned based on the first select box value. 然后,您可以简单地使用CSS选择器$('#secondDiv).html(result)加载内容。这里的结果是根据第一个选择框值返回的下拉内容。 Hope you understand this ! 希望你能理解!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM