11

我得到这个错误,我不知道为什么?

错误号:1052
where 子句中的列 'id' 不明确

SELECT `leads`.*,
       `customers`.`id` AS customers_id,
       `customers`.`name` AS customers_name,
       `customers`.`company` AS customers_company,
       `customers`.`email` AS customers_email,
       `customers`.`phone` AS customers_phone,
       `customers`.`created_at` AS customers_created_at,
       `customers`.`updated_at` AS customers_updated_at,
       `customers`.`ip_address` AS customers_ip_addressFROM (`leads`)
JOIN `customers` ON `customers`.`id` = `leads`.`customer_id`
WHERE `id` = '3'
  AND `leads`.`id` = '1'LIMIT 1

文件名:/home/www/REMOVED/models/lead.php

行号:12

该函数如下所示:

function get($id)
{
  $this->db->select('leads.*, customers.id AS customers_id, customers.name AS customers_name, customers.company AS customers_company, customers.email AS customers_email, customers.phone AS customers_phone, customers.created_at AS customers_created_at, customers.updated_at AS customers_updated_at, customers.ip_address AS customers_ip_address');
  $this->db->where('leads.id', '1');
  $this->db->from('leads');
  $this->db->join('customers', 'customers.id = leads.customer_id');
  $this->db->limit(1);
  $query = $this->db->get();

  if ($query->num_rows() == 1)
  {
    $result = $query->result();
    return $result[0];
  }
}

第 12 行是$query = $this->db->get();

怎么了?

4

1 回答 1

26
WHERE id = '3'

您没有指定 id 字段来自哪个表。你的意思:

WHERE customer.id = '3'

条件将是 customer.id 而不是 id

于 2014-03-25T11:04:53.030 回答