Zaimplementowałem proste zapytanie w moim modelu:
$condition = "id="$user_id" AND (role="admin" OR role="manager" OR role="staff")" ;
$this->db->select("password,ref_id,role");
$this->db->from("user");
$this->db->where($condition);
$query = $this->db->get();
return $query->row_array();
Wystąpił jednak następujący błąd:
Error Number: 1054
Unknown column "id="1"" in "where clause"
SELECT `password`, `ref_id`, `role` FROM (`user`) WHERE `id="1"` AND (role="customer" OR role="supplier")
Filename: D:MYSERVERwampwwwsystemdatabaseDB_driver.php
Line Number: 330
Co jest nie tak?
Odpowiedzi:
0 dla odpowiedzi № 1Możesz spróbować tego:
$this->db->where($condition, NULL, false);
W powyższej składni pierwsza jest dla condition
, drugi parametr dotyczy value
który jest NULL
tutaj, a trzeci jest dla wyjścia z ciągu (domyślnie jest to prawda).
0 dla odpowiedzi nr 2
$this->db->select("password,ref_id,role");
$this->db->from("user");
$this->db->where("id", $user_id);
$this->db->where("role", "manager");
$this->db->where_or("role", "staff");
LUB w przypadku Twojego kodu, gdzie nie działa. Jeśli dodajesz polecenie sql, musisz podać również inne parametry. Spróbuj poniżej -
$this->db->where($condition, NULL, FALSE);