teknojunkey Posted October 12, 2009 Share Posted October 12, 2009 Hi I want to enter the same data into two tables, this is how i am trying to do it ... foreach ($data['celeb_description'] as $language_id => $value) { $this->db->query("INSERT INTO " . DB_PREFIX . "celeb_description SET celeb_id = '" . (int)$celeb_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "celeb SET cname = '" . $this->db->escape($value['name']) . "'"); } this adds the data to the table ... however creates a second row in the table with blank details. what is the best way to do this ? thanks Link to comment https://forums.phpfreaks.com/topic/177364-solved-enter-into-two-tables/ Share on other sites More sharing options...
teknojunkey Posted October 12, 2009 Author Share Posted October 12, 2009 here is the full function: public function addCeleb($data) { $this->db->query("INSERT INTO " . DB_PREFIX . "celeb SET parent_id = '" . (int)$data['parent_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW(), date_added = NOW()"); $celeb_id = $this->db->getLastId(); if (isset($data['image'])) { $this->db->query("UPDATE " . DB_PREFIX . "celeb SET image = '" . $this->db->escape($data['image']) . "' WHERE celeb_id = '" . (int)$celeb_id . "'"); } foreach ($data['celeb_description'] as $language_id => $value) { $this->db->query("INSERT INTO " . DB_PREFIX . "celeb_description SET celeb_id = '" . (int)$celeb_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', description = '" . $this->db->escape($value['description']) . "'"); $this->db->query("INSERT INTO " . DB_PREFIX . "celeb SET cname = '" . $this->db->escape($value['name']) . "'"); } if ($data['keyword']) { $this->db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'celeb_id=" . (int)$celeb_id . "', keyword = '" . $this->db->escape($data['keyword']) . "'"); } $this->cache->delete('celeb'); } Link to comment https://forums.phpfreaks.com/topic/177364-solved-enter-into-two-tables/#findComment-935414 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.