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

时间:2012-12-23 07:52:56

标签: php mysql ajax

我有一个用户选择公司和日期的表单。然后,用户需要从数据库中选择一些库存,并将记录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>

如果这有意义,请告诉我。如果不是,我会改变我的问题

1 个答案:

答案 0 :(得分:0)

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

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