amwd07 Posted November 14, 2008 Share Posted November 14, 2008 Hello I have been struggling now for the past 4hrs to print_r element so I can enter the elements into the DB. I am trying to fetch all the sub categories for a particualar category so all [categories] should be entered into the DB currently Array shows in the DB ??? Object ( [_data] => Array ( [recordcount] => 31 [outofstock] => 17 [instock] => 14 [nopages] => 1 [categories] => Array ( [Accessories] => 7 [LCD] => 1 [LCD TV] => 1 [Media and Play] => 5 [Media Center] => 4 [Photo Frame] => 1 [Remote Control] => 3 [switch] => 3 [TV Tuner] => 5 [Wireless] => 1 ) I have tried various methods // 1ST attempt $subcat = current($this->_data['categories']); $first_array = array("categories" => $subcat); echo $first_array['categories']; // second attempt print_r($this->_data['categories']); // third attempt echo $this->_data['categories'][] = array tried other things but no use Please anyone any idea's? Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/ Share on other sites More sharing options...
foxtrotwhiskey Posted November 14, 2008 Share Posted November 14, 2008 I'm sorry, could you clarify? I'm not exactly sure what you are trying to do.. Please be as detailed as possible. Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/#findComment-690456 Share on other sites More sharing options...
Barand Posted November 14, 2008 Share Posted November 14, 2008 Object ( [_data] => Array ( [recordcount] => 31 [outofstock] => 17 [instock] => 14 [nopages] => 1 [categories] => Array ( [Accessories] => 7 [LCD] => 1 [LCD TV] => 1 [Media and Play] => 5 [Media Center] => 4 [Photo Frame] => 1 [Remote Control] => 3 [switch] => 3 [TV Tuner] => 5 [Wireless] => 1 ) What was the statement that gave the above output? Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/#findComment-690470 Share on other sites More sharing options...
amwd07 Posted November 14, 2008 Author Share Posted November 14, 2008 right now I have got further foreach($this->_data['categories'] as $cat_name => $cat_count) { // subcategory does not exists! $fields_cat = array("id_subcat" => $id_subcat, "id_xpress_cat" => $data['item_category'], // added to insert xpress category ID! "subcat_name" => $cat_name, // "link_rewrite" => urlfriendly($data['categories']), "active" => '1', "date_add" => NOW, "date_upd" => NOW); $id_subcat = dbInsert(WEBZSQL_DB_PREFIX."xpress_subcategory",$fields_cat); $addsubcat = true; } this enters Accessories into the DB and enters LCD 29 times for some reason giving these errors SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '31' for key 1] 1: AM-ST100H-BRACKET updated. SQL/DB Error -- [Duplicate entry '31' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '32' for key 1] 2: BL-AV24105QP updated. SQL/DB Error -- [Duplicate entry '32' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] SQL/DB Error -- [Duplicate entry '33' for key 1] Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/#findComment-690472 Share on other sites More sharing options...
Barand Posted November 14, 2008 Share Posted November 14, 2008 You are trying to add records with key values 31,32,33 but records with those key values already exist Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/#findComment-690476 Share on other sites More sharing options...
amwd07 Posted November 14, 2008 Author Share Posted November 14, 2008 why would this happen if I am looping? example DB ID Parent SubCat Active 31 493 Accessories 1 32 493 LCD 1 33 493 LCD 1 34 493 LCD 1 but there are about 10 categories so why does this duplicate after the 1st one? Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/#findComment-690478 Share on other sites More sharing options...
amwd07 Posted November 14, 2008 Author Share Posted November 14, 2008 right the category name is working but without id_xpress_cat with that in it produces 300 categories foreach($this->_data['categories'] as $cat_name => $cat_count) { // subcategory does not exists! $fields_cat = array("id_xpress_cat" => $data['item_category'], // added to insert xpress category ID! "subcat_name" => $cat_name, // "link_rewrite" => urlfriendly($data['categories']), "active" => '1', "date_add" => NOW, "date_upd" => NOW); $id_subcat = dbInsert(WEBZSQL_DB_PREFIX."xpress_subcategory",$fields_cat); $addsubcat = true; } Link to comment https://forums.phpfreaks.com/topic/132767-solved-print_r-element-in-array/#findComment-690485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.