我正在開(kāi)發(fā)用于 oop php 中的屬性/廣告的 cms 以用于學(xué)習(xí)目的。我有三個(gè)與數(shù)據(jù)透視表相連的表。photos (name, extension, created_at, updated_at), property_photo (property_id, photo_id), properties (title, description, type_of_property, use_of_the_property, quadrature, location...) 當(dāng)我嘗試通過(guò)添加另一張照片來(lái)更新我的屬性時(shí),在我的數(shù)據(jù)透視表中 photo_id 從照片表中獲取正確的 id,但我的 property_id 始終為 0。現(xiàn)在我知道 lastInsertId 函數(shù)僅在 INSERT 上不能用于 UPDATE 但我不知道如何以不同的方式獲取 property_id。任何幫助表示贊賞。這是我在模型中的功能:廣告模型:public function update_ad($data, $id){ $this->db->query('UPDATE properties SET title=:title, description=:description, type_of_property=:type_of_property, use_of_the_property=:use_of_the_property, quadrature=:quadrature, location=:location, price=:price, sales_clerk_info=:sales_clerk_info, booked=:booked, type_of_market=:type_of_market, type_of_payment=:type_of_payment WHERE id=:id'); $this->db->bind(':title', $data['title']); $this->db->bind(':description', $data['description']); $this->db->bind(':type_of_property', $data['type_of_property']); $this->db->bind(':use_of_the_property', $data['use_of_the_property']); $this->db->bind(':quadrature', $data['quadrature']); $this->db->bind(':location', $data['location']); $this->db->bind(':price', $data['price']); $this->db->bind(':sales_clerk_info', $data['sales_clerk_info']); $this->db->bind(':booked', $data['booked']); $this->db->bind(':type_of_market', $data['type_of_market']); $this->db->bind(':type_of_payment', $data['type_of_payment']); $this->db->bind(':id', $id); $this->db->execute(); $property_last_id = $this->db->lastId(); $dataimagecount = count($data['image']); for ($i=0; $i < $dataimagecount ; $i++) { $extension[$i] = explode('.',$data['image'][$i]); $this->db->query('INSERT INTO photos (name, extension) VALUES (:name, :extension)'); $this->db->bind(':name', $extension[$i]['0']); $this->db->bind(':extension', $extension[$i]['1']); $this->db->execute();
- 1 回答
- 0 關(guān)注
- 161 瀏覽
添加回答
舉報(bào)
0/150
提交
取消