Php下拉没有给出正确的价值观

时间:2015-04-07 03:04:42

标签: php

我是PHP的初学者,我正在尝试建立一个库存管理系统。这是我的仓库名称下拉列表和项目名称的另一个下拉列表。当我选择仓库下拉列表时,我可以看到该仓库的库存;但是,当我选择特定产品时,我什么也看不见。

非常感谢!!

function ViewWarehouseItems()
    {
?>
    <div class="navigation">
        <h2> View the Inventory</h2>
    </div>
    <p>Select a Warehouse Location</p>
    <script>
        function get_Items(value) 
                    {
                      if (window.XMLHttpRequest) 
                          {
                            xmlhttp=new XMLHttpRequest();
                          } 
                      else 
                          { 
                            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                          }
                      xmlhttp.onreadystatechange=function() 
                          {
                            if (xmlhttp.readyState==4 && xmlhttp.status==200) 
                                {
                                  document.getElementById("table").innerHTML=xmlhttp.responseText;
                                }
                          }
                      xmlhttp.open("GET","getitems.php?id="+value,true);
                      xmlhttp.send();
                    }                       
    </script>
    <form>
        <select name='warehouse_location' onchange="get_Items(this.value)">
        <option value='0'>..Select..</option>
    <?php 
    $sql="SELECT * from warehouses"; 
    $result=$this->connection_string->query($sql);
            while ($row = $result->fetch_assoc())
        {
            $warehouse_id=$row['warehouse_id'];
            $warehouse_location=$row['warehouse_location'];
    ?>
            <option value="<?php echo $warehouse_id; ?>"><?php echo $warehouse_location; ?></option>
                            <?php
        }
        ?>
    </select>
    </form>
    <p>Select an Item</p>
    <form>
    <select name='item_name' onchange="get_Items(this.value)">
    <option value='0'>..Select an item..</option>
    <?php 
        $sql="SELECT * from items"; 
        $result=$this->connection_string->query($sql);
            while ($row = $result->fetch_assoc())
        {
            $item_id=$row['item_id'];
            $item_name=$row['item_name'];
            ?>
        <option value="<?php echo $item_id; ?>"><?php echo $item_name; ?></option>
    <?php
        }
        ?>
    </select>
    </form>
    <?php echo "<br>"."<br>" ?>
    <div id="table"></div>
        <?php
}

这是我在上面的函数中使用的另一个php文件。

<!DOCTYPE html>
<html>
<body>
<?php
$id = intval($_GET['id']);
echo $id;
include_once "dbConnect.php";
include_once "items.php";
include_once "warehouse.php";

$sql="SELECT * FROM items WHERE warehouse_id = $id";
$result = mysqli_query($conn,$sql); 
?>
        <div class="forum_header">
        <div class="item_topics_header">Warehouse ID</div>
        <div class="item_topics_header">Warehouse Location</div>
        <div class="item_topics_header">Item ID</div>
        <div class="item_topics_header">Item Name</div>
        <div class="item_topics_header">Inventory</div>
        </div>
<?php
$item_obj=new Items($conn);
$warehouse_obj=new Warehouse($conn);

while($row = mysqli_fetch_array($result)) {
            $warehouse_id=$row['warehouse_id'];
            //$warehouse_location=$row['warehouse_location'];
            $wl=$warehouse_obj->GetWarehouseLocation($warehouse_id);
            $item_id=$row['item_id'];
            $i=$item_obj->GetItemName($item_id);
            //$item_name=$row['item_name'];
            $item_quantity=$row['item_quantity'];
            ?>
            <div class="forum_lines">
            <div class="item_replies_header"><?php echo $warehouse_id; ?></div>
            <div class="item_replies_header"><?php echo $wl; ?></div>
            <div class="item_replies_header"><?php echo $item_id; ?></div>
            <div class="item_replies_header"><?php echo $i; ?></div>
            <div class="item_replies_header"><?php echo $item_quantity; ?></div>
            </div>
    <?php
}
mysqli_close($conn);
?>
</body>

2 个答案:

答案 0 :(得分:0)

似乎您需要为getitems.php添加一些额外的功能,以检查您是否通过了仓库或产品。所以传递某种名称可以帮助你确定传递哪种“类型”的id。

现在,你getitems.php假设它只是一个仓库,而不是任何进一步的,基于你的查询。

答案 1 :(得分:0)

所以你会做这样的事情:

<option value="i_<?php echo $item_id; ?>">

<option value="wh_<?php echo $warehouse_id; ?>">

然后修改脚本以执行以下操作:

$temp_id = explode("_", $_GET['id']);

$type = $temp_id[0];
$id = $temp_id[1];

最后这个:

if($type === 'wh'){

   $sql="SELECT * FROM items WHERE warehouse_id = $id";

}
else if($type === "i"){
   $sql="SELECT * FROM items WHERE id = $id";
  // MODIFY id to be the proper name for an item_id
}