Web Design Forum: Setting new table in Opencart - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Setting new table in Opencart Rate Topic: -----

#1 User is offline   Gaelen 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 231
  • Joined: 28-September 11
  • Reputation: 6
  • Gender:Male
  • Location:Coquitlam, BC, Canada
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 09 January 2012 - 05:07 PM

I'm having an issue getting the manufacturer_id to set in each table when I insert a new one. For some reason it only sets in the original table and I cant figure out why.

public function addManufacturer($data) {
      	$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer SET name = '" . $this->db->escape($data['name']) . "', sort_order = '" . (int)$data['sort_order'] . "'");
		
		$manufacturer_id = $this->db->getLastId();

		if (isset($data['image'])) {
			$this->db->query("UPDATE " . DB_PREFIX . "manufacturer SET image = '" . $this->db->escape($data['image']) . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
		}
		if ($data['map']) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer_contact SET contact = '" . $this->db->escape($data['contact']) . "', phone = '" . $this->db->escape($data['phone']) . "', email = '" . $this->db->escape($data['email']) . "', address = '" . $this->db->escape($data['address']) . "', country = '" . $this->db->escape($data['country']) . "', code = '" . $this->db->escape($data['code']) . "', account = '" . $this->db->escape($data['account']) . "', rep_phone = '" . $this->db->escape($data['rep_phone']) . "', rep_cell = '" . $this->db->escape($data['rep_cell']) . "', account = '" . $this->db->escape($data['account']) . "', fax = '" . $this->db->escape($data['fax']) . "', csr_name = '" . $this->db->escape($data['csr_name']) . "', csr_phone = '" . $this->db->escape($data['csr_phone']) . "', csr_email = '" . $this->db->escape($data['csr_email']) . "', csr_fax = '" . $this->db->escape($data['csr_fax']) . "', map = '" . (int)$data['map'] . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
		}

0

#2 User is offline   simonkincaid 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 09-January 12
  • Reputation: 1

Posted 09 January 2012 - 05:25 PM

I'm not amazing at OpenCart but taking a look at your code that addManufacturer function is only creating one new row in your table from DB_PREFIX. Maybe your questions is worded incorrectly? There's nowhere else where the ID is being inserted or 'set'.
0

#3 User is offline   Gaelen 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 231
  • Joined: 28-September 11
  • Reputation: 6
  • Gender:Male
  • Location:Coquitlam, BC, Canada
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 09 January 2012 - 05:38 PM

I've been looking for somewhere to set the id, but as far as I can see it's created upon making a new table... however I cant figure out where to add a new table to create the same id. I've created 3 new tables but they are not being populated once I add a manufactiurer
0

#4 User is offline   simonkincaid 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 15
  • Joined: 09-January 12
  • Reputation: 1

Posted 10 January 2012 - 09:38 AM

View PostGaelen, on 09 January 2012 - 05:38 PM, said:

I've been looking for somewhere to set the id, but as far as I can see it's created upon making a new table... however I cant figure out where to add a new table to create the same id. I've created 3 new tables but they are not being populated once I add a manufactiurer


You are still not making sense with this.

The manufacturerID is created when you create a new 'row' in the table.

$manufacturer_id = $this->db->getLastId();


The above gives you the id of the row that was just inserted.

The easiest thing to do is start from the beginning.

What is the structure of all the tables that you are dealing with?
1

#5 User is offline   Gaelen 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 231
  • Joined: 28-September 11
  • Reputation: 6
  • Gender:Male
  • Location:Coquitlam, BC, Canada
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 10 January 2012 - 05:26 PM

I realized that about 30min after I posted this, got it all working great now! thanks :D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users