这有什么不对? SQL查询给我一个错误1146

时间:2012-11-01 12:19:47

标签: sql mysql-error-1146

我正在尝试使用来自一个表(聚会)的每一行的所有列,以及来自另一个表(客户)的一些列。

好的,这是我的代码

public function getParty($data = array()) {

    $sql = "SELECT party.* , customer.customer_id AS customerID, customer.firstname AS customerFN, customer.lastname AS customerLN, customer.email AS customerEMAIL, customer.ip AS cutomerIP
    FROM `" . DB_PREFIX . "party` 
    JOIN `" . DB_PREFIX . "cutomer` 
    ON party.cutomer_id = customer.customer_id
    WHERE status=3";

    $sort_data = array(


        'date_added',
        'order_id',
        'customer_id',
        'customerFN',
        'customerLN',
        'customerEMAIL',
        'customerIP',
        'description',
        'status',
        'amount'


    );

    if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
        $sql .= " ORDER BY " . $data['sort'];   
    } else {
        $sql .= " ORDER BY date_added"; 
    }

    if (isset($data['order']) && ($data['order'] == 'DESC')) {
        $sql .= " DESC";
    } else {
        $sql .= " ASC";
    }

    if (isset($data['start']) || isset($data['limit'])) {
        if ($data['start'] < 0) {
            $data['start'] = 0;
        }           

        if ($data['limit'] < 1) {
            $data['limit'] = 20;
        }   

        $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
    }

    $query = $this->db->query($sql);

    return $query->rows;
}

这是错误

Notice: Error: Table 'XXX.cutomer' doesn't exist
Error No: 1146
SELECT party.* , customer.customer_id AS customerID, customer.firstname AS customerFN, customer.lastname AS customerLN, customer.email AS customerEMAIL, customer.ip AS cutomerIP FROM `party` JOIN `cutomer` ON party.cutomer_id = customer.customer_id WHERE status=3 ORDER BY date_added ASC LIMIT 0,10 in /srv/www/htdocs/XXX/system/database/mysql.php on line 49

也许我错了,但看不到它

问候 Petar Stoyanov

4 个答案:

答案 0 :(得分:1)

JOIN `" . DB_PREFIX . "cutomer` 

应该是

JOIN `" . DB_PREFIX . "customer` 

也...

ON party.cutomer_id = customer.customer_id

应该是

ON party.customer_id = customer.customer_id

我会搜索cutomer的所有实例,并将其替换为customer

答案 1 :(得分:0)

我认为应该是

ON party.customer_id = customer.customer_id

而不是

ON party.cutomer_id = customer.customer_id

答案 2 :(得分:0)

请从

更改
    JOIN `" . DB_PREFIX . "cutomer` 

    JOIN `" . DB_PREFIX . "customer` 

前:

    FROM `" . DB_PREFIX . "party` 
    JOIN `" . DB_PREFIX . "customer` 
    ON party.cutomer_id = customer.customer_id
    WHERE status=3";

答案 3 :(得分:-1)

将SQL stmt更改为:

$sql = "SELECT party.* , customer.customer_id AS customerID, customer.firstname AS customerFN, customer.lastname AS customerLN, customer.email AS customerEMAIL, customer.ip AS customerIP
FROM `" . DB_PREFIX . "party` 
JOIN `" . DB_PREFIX . "customer` 
ON party.customer_id = customer.customer_id
WHERE status=3";