Jump to content

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

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.