dongmeng0317 2016-04-13 09:29
浏览 65

您如何查看订单中的库存情况?

My issue: I am trying to make an system which checks if orders has their items in stock. I am using 3 databases for this.

Products Database:
Product ID  Name    Disposable
ABC123      Chair   15
AFG999      Table   1
CHO555      Sofa    15

Order Details:
ID    Customer ID    Date
1555  123            2016-04-12
2666  333            2016-04-13

Order Details: 
ProductID    Quantity    OrderID
ABC123       5           1555
CHO555       2           2666
AFG999       2           2666

What I'm trying to achieve is that it iterates through the ordered products and checks if they are in stock. Also imagine that some orders will have over 20 products on them, how would I do this most efficiently?

What I have tried:

I have tried to solve it by iterating through the order details database and splitting them by a comma "," in php, like so:

$getorderdetails = mysqli_query($connect, 
"SELECT corders.id, GROUP_CONCAT(corderdetails.productid) as productid,
 GROUP_CONCAT(corderdetails.quantity) AS quantity
        FROM corders, corderdetails
        WHERE corders.id = corderdetails.orderid
        GROUP BY corders.id
        ORDER BY corders.id");

This outputs something like this:

Order ID    Ordered Products    Ordered Quantity
2666        CHO555,AFG999       2,2

So I tried splitting it up in arrays and searching the database one by on but I never really got it to work and I was wondering if someone else may share their solution?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?