2014-03-25 10 views
5

Ich bekomme diesen Fehler und ich kann nicht herausfinden, warum?Spalte 'ID' in Where-Klausel ist mehrdeutig

Fehlernummer: 1052
Spalte 'id' in where-Klausel ist nicht eindeutig

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 

Dateiname: /home/www/REMOVED/models/lead.php

Zeilennummer: 12

T er Funktion sieht wie folgt aus:

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]; 
    } 
} 

und Linie 12 ist $query = $this->db->get();

Was ist falsch?

Antwort

11
WHERE id = '3' 

Sie geben nicht an, aus welcher Tabelle das ID-Feld stammt. Meinten Sie:

WHERE customer.id = '3' 
+0

Ich spezifiziere es in meinem Code? $ this-> db-> join ('Kunden', 'customers.id = leads.customer_id'); – Casperlarsen

+0

das ist die Join-Klausel - schauen Sie sich die WHERE-Klausel in Ihrem SQL-Beispiel an - es ist genau dort –

+0

Aber in meinem Code, den ich die Tabelle angeben? $ this-> db-> where ('leads.id', '1'); – Casperlarsen

Verwandte Themen