使用AJAX下拉字段搜索并添加到数组以实时显示结果


Use AJAX dropdown field search and add to array to show results live

我有一个表单,用户在其中选择公司和日期。然后,用户需要从数据库中选择一些库存,并将记录id添加到一个数组中以供以后使用。我的想法是简单地获取每个库存项目的id并将其传递给一个数组,这样我就可以稍后循环插入mysql。我希望能够让用户搜索从一个字段的库存,然后结果显示在该字段下面,然后用户可以选择该特定的库存项目。当他们点击/选择它时,它会将记录id添加到一个数组中,我可以稍后播放。

<form action="" method="post">
    <div>
    <select>
        <option>Company 1</option>
        <option>Company 2</option>
    </select>
    </div>
    <div>
        <input type="text" name="date">
    </div>
    <div>
        <input type="text" name="search">
        // Here is where I need to display the results from the db based on what the user typed in a drop down, then when that user selects that item then it will add that records id to an array. Then I need the array to display below and how the records based on the id. 
    </div>
    <div>
    // The array is shown here and as the user selects multiple items. It might look something like this
    <? $thisarray = array() - as users select items from drop down then the records ids are added to the array. Then as they are added to the array I can use a mysql SELECT to display those records. Then when the user submits the form I can pass that array as well.
    </div>
</form>

请让我知道这是否有意义。如果没有,我将更改问题

如果你的serial_number可以是一个字符串,也许你可以使用uuid(通用唯一标识符)与前缀。

http://php.net/manual/en/function.uniqid.php