0

IMG

我想为每个制造商项目显示协议分销商选择字段。AGREEMENT DISTRIBUTOR 应仅包含分配给客户的分销商。每个客户都有协议。在上图中,我们为 id 为 43 的客户签订了 id/GroupID 为 1 的协议。

 agreement table
 id    GroupID
 1     1
 2     2

distribgroup table
id    groupid    custid
1     1          43

根据“cust2distrib”表将分销商分配给客户

       cust2distrib table

id    custid    distribid
1       43          11
2       43          10
3       43          9
4       41          11

 distributors table

id        name    
9        California    
10       Lincoln       
11       Atlanta      

用于获取正确分销商的代码(有多个分销商。我们只想查看分配给客户的分销商(参见上面的“cust2distrib”表):

SELECT *, b.id as id, e.name2 as distribname, e.id as distribid, c.groupid as groupID     from agreement b
LEFT JOIN distribgroup c
ON c.groupid = b.GroupID
LEFT JOIN cust2distrib d
ON d.custid = c.custid
LEFT JOIN distributors e
ON e.id = d.distribid
WHERE c.groupid = $id

在上图中,我们还显示了协议项目(项目编号、类型、折扣...等)...

agreement_items
id    groupID    item_number    item_description    din    type      discount 
1        1        111                Oranges        5                  2
2        1        222                Bananas        3     Delivered    5

...通过这个 php 代码:

<?php
$sql = "SELECT * from agreement_items WHERE GroupID = $id";
try 
    { 

        $stmt = $db->prepare($sql); 
        $stmt->execute(); 
    } 
    catch(PDOException $ex) 
    { 

        die("Failed to run query: " . $ex->getMessage()); 
    } 


    $rows = $stmt->fetchAll(); 


//Check each record from your query
foreach($rows as $row) { 

?>
HTML displaying manufacturer item, distributor item number, type, discount,
ceiling price goes here.

**I ALSO NEED "AGREEMENT DISTRIBUTOR" TO BE PLACED HERE FOR EACH ITEM. 
Agreement Distributor needs to be a select input with the option to choose
between all distributors assigned to the customer of which the agreement belongs to**
<?
}

所以...如果加利福尼亚、林肯、亚特兰大分配给客户 43并且我正在查看属于客户 43 的协议 1,我想在每个制造商项目的“协议分销商”下拉列表中显示加利福尼亚、林肯、亚特兰大(在协议项目表)

任何帮助将非常感激。谢谢!

4

0 回答 0