dongshanfan1941 2014-03-17 05:08
浏览 23
已采纳

如何检索所有信息当我选择一个值时

I have A question in php and jquery When i Select Itemname All information From item name are display on a textbox.. How To do this with jquery?

Here is my codes..

PHP

$iname = $mysqli->prepare("SELECT itemname,quantity,critical_level FROM table_inventory");
    $iname->execute();
    $iname->bind_result($itemname);
    $iname->store_result();

    $itemnames = array();

    while($iname->fetch())
    {
      $itemnames[] = $itemname;
    }


<form>
<div class="form-group ">
<label for="group" class="control-label col-lg-2">Item Name</label>
<div class="col-lg-10">
<select id="quantity"  name="quantity" class="form-control">
<option disabled selected>Item Name</option>
<?php foreach ($itemnames as $i): ?>
<option><?=$i?></option>
<?php endforeach; ?>
</select>

</div>
</div>
<div class="form-group ">
<label for="group" class="control-label col-lg-2">Quantity</label>
<div class="col-lg-10">
<input class=" form-control" required="required" name="group" type="text"  id="output"/>
</div>
</div>
<div class="form-group ">
<label for="group" class="control-label col-lg-2">Critical Level</label>
<div class="col-lg-10">
<input class=" form-control" required="required" name="group" type="text" />
</div>
</div>

</form

when I select from dropdown All the information from i selected are output in the textbox THANKS IN ADVANCE.. SORRY FOR THIS NEWBIE QUESTION

  • 写回答

1条回答 默认 最新

  • dongwujie7477 2014-03-17 05:26
    关注

    Here is a simple example, say you have a bunch of different Makes of cars, and you want it to automatically update with the corresponding models

    AJAX CODE that would go in your jQuery Assuming Make is a dropdown and Model is a <textarea id="model"></textarea>

    $("#make").change(function(){
        $.ajax({
            url: "http://yoursite.com/modelUpdate.php",
            data: {make: $(make).val()},
            type: "post",
            success: function(msg){
            $("#model").val(msg);
            }
        });
    });
    

    So when you change the make in the drop down the value of the make is sent up to modelUpdate.php

    Here is some simple PHP code you would need in modelUpdate.php I am not going to write the query out for you but I will show you how to return the data.

    $make = $_POST['make']; // This is the AJAX value that was selected on your page
    //DO YOUR QUERY HERE TO GET THE DATA
    echo $data; 
    

    Anything you echo on this PHP page will be returned and will set that <textarea id="model"></textarea> value.

    I hope this gets you started in the right direction

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)