Jump to content

[SOLVED] enter into two tables


teknojunkey

Recommended Posts

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

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');

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.