Jump to content

[SOLVED] print_r element in array


amwd07

Recommended Posts

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

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?

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]

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?

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;
			}	

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.