简体   繁体   English

在phpmyadmin中插入和重新计算表

[英]Inserting and recalculating table in phpmyadmin

i want to check and update "part" table. 我想检查并更新“零件”表。 So i have table "StockEntry" http://prntscr.com/gvkc60 i can compare them by part_id. 因此,我有“ StockEntry”表http://prntscr.com/gvkc60,我可以通过part_id比较它们。 And i have "part" table: http://prntscr.com/gvkcqd 我有“部分”表: http : //prntscr.com/gvkcqd

What i want to do is, when i insert export product on my site i use this code: 我想做的是,当我在自己的网站上插入导出产品时,使用以下代码:

<?php
        $servername = "localhost";
        $username = "xxxxx";
        $password = "xxxxx";
        $dbname = "xxxxx";
        $dateTimeVariable = date( "Y-m-d H:i:s" );
        $stock = -$_POST[ sto ];
        // Create connection
        $conn = new mysqli( $servername, $username, $password, $dbname );
        // Check connection
        if ( $conn->connect_error ) {
            die( "Connection failed: " . $conn->connect_error );
        }
        if ( !empty( $_POST[ 'vnos' ] ) ) {
            $sql = "INSERT INTO StockEntry (part_id, user_id, stockLevel, price, dateTime, correction, comment)
                    VALUES ('$_POST[vnos]', '3', '$stock', '', '$dateTimeVariable', '0', 'test')";

            if ( $conn->query( $sql ) === TRUE ) {
                echo "New record created successfully";
            } else {
                echo "Error: " . $sql . "<br>" . $conn->error;
            }
        }
        $conn->close();

        ?>

That code insert -1 stock or whatever i take out and sort them with part_ID, every product has own part_ID. 该代码插入-1库存或我取出的任何东西,并用part_ID对其进行排序,每个产品都有自己的part_ID。 After that i want to check "part" table and product with same id (so part_id = id) to change number.. let's say if i had 30 products when i take 10 table update number on 20. 之后,我想检查“零件”表和具有相同ID(所以part_id = id)的产品以更改编号。.假设我在20上获取10个表更新编号时是否有30个产品。

How can i do that? 我怎样才能做到这一点?

so basicly i can do id from "part" - part_id from "stcokEntry" but dont know how.. can you guys help me please? 所以基本上我可以从“ part”中获取id-从“ stcokEntry”中获取part_id,但不知道如何..你们可以帮我吗?

If someone could leave discord or mail or something to quick chat please i just need that 1 sentence.. need it by 3o'clock.. 如果有人可以留下不和谐或邮件或其他东西来快速聊天,请我只需要那一句话..需要在三点钟之前。

If you are storing the same stockLevel in both the tables, (assuming each stockLevel corresponds to a single part_id ), then you should just store/update it against that part_id in the Part table. 如果要在两个表中存储相同的stockLevel (假设每个stockLevel对应于一个part_id ),则应仅在Part表中针对该part_id存储/更新它。

And every time you are in need of the stockLevel for a given part_id , just join the StockEntry table with the Part table with a join query. 每次你都需要的时间stockLevel对于给定part_id ,只是加入StockEntry表的Part用联接查询表。 Something like 就像是

SELECT stockLevel 
    FROM StockEntry se
        LEFT JOIN Part p
            ON ( se.part_id = p.id);

Not sure if this is really what you needed. 不知道这是否真的是您所需要的。 But this concept is called Normalization (quite certain you already knew that). 但是这个概念叫做规范化 (肯定已经知道)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM