Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php “正在尝试查询客户”;“公司”;以Magento为单位的值1.7 DB_Php_Mysql_Sql_Magento - Fatal编程技术网

Php “正在尝试查询客户”;“公司”;以Magento为单位的值1.7 DB

Php “正在尝试查询客户”;“公司”;以Magento为单位的值1.7 DB,php,mysql,sql,magento,Php,Mysql,Sql,Magento,我一直在寻找一个解决办法,我发现的每件事对于我正在尝试的事情来说都过于复杂了 我正在尝试获取属于客户组2的所有客户的列表。据我所知,那部分很好用 接下来,我试图查找他们的订单并输出他们公司的名称。在这里,我认为我的代码中有一个错误导致挂起 因此,最终目标是列出属于第2组的客户的所有公司名称 我试图通过SQL查询来实现这一点。网页在加载时会挂起。有一次我让它显示一些数据,但它是不完整的 下面是我所拥有的。你能看一下,看看有什么问题吗?我希望有一个不合适的地方;或者类似的 *出于安全原因,我没有粘贴

我一直在寻找一个解决办法,我发现的每件事对于我正在尝试的事情来说都过于复杂了

我正在尝试获取属于客户组2的所有客户的列表。据我所知,那部分很好用

接下来,我试图查找他们的订单并输出他们公司的名称。在这里,我认为我的代码中有一个错误导致挂起

因此,最终目标是列出属于第2组的客户的所有公司名称

我试图通过SQL查询来实现这一点。网页在加载时会挂起。有一次我让它显示一些数据,但它是不完整的

下面是我所拥有的。你能看一下,看看有什么问题吗?我希望有一个不合适的地方;或者类似的

*出于安全原因,我没有粘贴连接详细信息,但代码确实没有问题地连接到数据库。

<?php
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } 



//Run a Query to get all wholesale customer IDs

$sql1 = "SELECT * FROM `customer_entity` WHERE `group_id` = 2";
$customerIDs = $conn->query($sql1);


    //so now that we have the wholesale customer IDs we are going to search 
    their orders for their company names.
    while( $row1 = $customerIDs->fetch_assoc() )
    {



        //Run a query to get a list of orders that the customer has placed
        $sql2 = "SELECT * FROM `sales_flat_order_address` WHERE 
        `customer_id` = " . $row1["entity_id"] ."";
        $customerOrders = $conn->query($sql2);


        // Echo the orders company name
        while( $row2 = $customerOrders->fetch_assoc() )
        {


            //Check to see if the name is NULL 
            if($row2['company'] !== NULL)
            {
                //display the company name.
                echo $row2['company'] . "</br>";

            }

        }



}

//close the connection
mysqli_close($conn);

?>

最终目标是列出属于第2组的客户的所有公司名称

您可以通过一个简单的
JOIN
ed查询来实现这一点。从您的代码来看,这应该是:

SELECT DISTINCT s.company
FROM 
    customer_entity c
    INNER JOIN sales_flat_order_address s ON s.customer_id = c.entity_id
WHERE c.group_id = 2

此查询将检索组2中的所有用户,然后选择他们的所有订单,最后输出所有(不同的)对应公司。

非常感谢。我需要学习和学习更多关于连接查询的知识。看来我把事情搞得太复杂了。谢谢,谢谢,谢谢,谢谢。