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'

条件はidではなくcustomer.idになります

于 2014-03-25T11:04:53.030 に答える