Problem printing what I want from a list of items

I am trying to print out information from a list. I thought I had this figured out but realized It was just printing out the same information over and over.
This is from a Joomla website and I am using the J2store extension, just to give you the information from where this is coming from.

So this is suppose to print out all the attributes from a single order. Each item in the order has any number of attributes that make it up. I am using it as an assembly site. So each assembly will have different attributes that make it up. (Hope that explains it good enough.)

[code][php]

<?php JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_j2store/models'); $model = JModelLegacy::getInstance( 'OrderItemAttributes', 'J2StoreModel' ); ?> <?php foreach (@$items as $item) : ?> <?php //these are just printed to show the 5 different items in the same order echo $item->order_id; echo '
'; echo $item->orderitem_id; echo '
'; echo $item->orderitem_name; echo '
'; $model->setState( 'filter_orderitemid', $item->orderitem_id); $attributes = $model->getList(); foreach($attributes as $attribute) { if(!empty($attribute->orderitemattribute_value)) { echo $attribute->orderitemattribute_name.' : '.$attribute->orderitemattribute_value; echo '
'; } } echo '
'; ?> <?php endforeach; ?>

[/php][/code]

This ends up printing out this:


1402100770
49
16" Box to Stud Bracket with Open Back Box + Modular Duplex
BRACKET : B-Line BB7-16
BOX : Crouse Hinds TP40DPF
Mud Ring (Choose an Option) : 3/4’’ Rise Single Gang
MC Cable (Choose an Option) : 12/2 (black,white,green) x 25’ L
Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector
Device Color (Choose an Option) : White
MC Connector (x2) : Crouse Hinds 38MCQ
12/2 Anti-Short (x2) : 12/2 Anti Short
11" Cable Tie (x2) : 11’’ Cable Tie
4 Port Wago (x3) : Ideal Model 88
Device Protector Plate : B-Line BPR1

1402100770
52
3/4" Conduit Masonry Stub
BRACKET : B-Line BB7-16
BOX : Crouse Hinds TP40DPF
Mud Ring (Choose an Option) : 3/4’’ Rise Single Gang
MC Cable (Choose an Option) : 12/2 (black,white,green) x 25’ L
Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector
Device Color (Choose an Option) : White
MC Connector (x2) : Crouse Hinds 38MCQ
12/2 Anti-Short (x2) : 12/2 Anti Short
11" Cable Tie (x2) : 11’’ Cable Tie
4 Port Wago (x3) : Ideal Model 88
Device Protector Plate : B-Line BPR1

1402100770
53
3/4" Conduit Masonry Stub
BRACKET : B-Line BB7-16
BOX : Crouse Hinds TP40DPF
Mud Ring (Choose an Option) : 3/4’’ Rise Single Gang
MC Cable (Choose an Option) : 12/2 (black,white,green) x 25’ L
Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector
Device Color (Choose an Option) : White
MC Connector (x2) : Crouse Hinds 38MCQ
12/2 Anti-Short (x2) : 12/2 Anti Short
11" Cable Tie (x2) : 11’’ Cable Tie
4 Port Wago (x3) : Ideal Model 88
Device Protector Plate : B-Line BPR1

1402100770
51
MC Cable Whip Assembly
BRACKET : B-Line BB7-16
BOX : Crouse Hinds TP40DPF
Mud Ring (Choose an Option) : 3/4’’ Rise Single Gang
MC Cable (Choose an Option) : 12/2 (black,white,green) x 25’ L
Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector
Device Color (Choose an Option) : White
MC Connector (x2) : Crouse Hinds 38MCQ
12/2 Anti-Short (x2) : 12/2 Anti Short
11" Cable Tie (x2) : 11’’ Cable Tie
4 Port Wago (x3) : Ideal Model 88
Device Protector Plate : B-Line BPR1

1402100770
50
Span Bracket with 4 SQ. Deep 1/2’’-3/4’’ KO’s + Modular 2 Single
BRACKET : B-Line BB7-16
BOX : Crouse Hinds TP40DPF
Mud Ring (Choose an Option) : 3/4’’ Rise Single Gang
MC Cable (Choose an Option) : 12/2 (black,white,green) x 25’ L
Device (Choose an Option) : Hubbell 20A SnapConnect Duplex with Connector
Device Color (Choose an Option) : White
MC Connector (x2) : Crouse Hinds 38MCQ
12/2 Anti-Short (x2) : 12/2 Anti Short
11" Cable Tie (x2) : 11’’ Cable Tie
4 Port Wago (x3) : Ideal Model 88
Device Protector Plate : B-Line BPR1


The number ‘1402100770’ is the order number. Which in that order there were 5 items purchased. The numbers for the orderitem_id are the correct numbers for the order number. The name is also the correct for the items that were in the order.
The problem is when the attributes print out. It prints the same attributes for all 5 items purchased.
It seems to be printing the first items attributes for all the items in the order.

I can’t figure out why the orderitem_id and orderitem_name all prints out correctly but when it prints of the attributes it just prints the same attributes for all the items in the order.

This is few days old. Did you solve it yet?

If not, I would look at lines 20-21. Either the setState() or getList() is not working correctly.
It is not loading your attributes as you wish. I would look at these two functions and see what they
require for inputs (arguments) to see if you are sending the correct item ID to them. It is obvious that
they are not pulling new data at each item print loop.

No still haven’t got it.

But I found the getList() function in the code:

[php] /** * Retrieves the data for a paginated list * @return array Array of objects containing the data from the database */ public function getList($refresh = false) { if (empty( $this->_list ) || $refresh) { $query = $this->getQuery($refresh); $this->_list = $this->_getList( (string) $query, $this->getState('limitstart'), $this->getState('limit') ); } return $this->_list; } [/php]

And the setState() function:

[php] function setState( $property, $value=null ) { return $this->_state->set($property, $value); } [/php]

It makes the list here, right?

[code]
[php]

$model->setState( 'filter_orderitemid', $item->orderitem_id);	
$attributes = $model->getList();

[/php][/code]

I want to build a list of all attributes from the ‘order_id’. I changed the orderitem_id to order_id. But the result was a longer list of attributes that didn’t relate to the particular ‘order_id’.

Okay, in the last posted code seems to be setting the parms that are used in the query.
So, it sets the “filter” for the order items to be “orderitem_id”.
Then, it calls the “getlist()” function which appears to just load the data into the array.
(It uses a “limitstart” and “limit” for setting some sort of limit to the data that it loads to return)

Have you looked at the actual data that is created from the line:
$attributes = $model->getList();
???

So, this start all of the function calls… Working back we see it pulls data using some status states and
limits. And, either this data is NOT pulling the correct items, in which case we need to back up further in
your code to see where the “getQuery($refresh)” pulls the data out of the query. OR, it is pulling the
correct data and it is not displaying it correctly. To prove that one way or another, you just have to print
the data and read down it to see if it has the same data for each item. Did that make sense?

So, where the above line is, just add a couple lines to display the data. Review it and look thru it to find
two different items and see if the attributes are the same for each…
Something like:
$attributes = $model->getList();
print_r($attributes);
die(“DONE”);
This will show what is INSIDE of the attributes. If the data is correct and different for each item, then the
display routines are messed up. If they are the same for each item, we need to look at the query itself.

Yikes. I may not have helped, but, we have a way to debug it… Good luck…

Alright I tested what the array had in it like you suggested.

What printed out was just information from the first item in the order.

I tried a few different ways to get it to do what I want. Then I searched through the code that was already there and found pretty much what I wanted, after some alteration. (Though I don’t understand exactly how it works.)

This is the code:

<?php foreach (@$items as $item) : ?>
						
                            <?php
                            	
                            	$registry = new JRegistry;
                            	$registry->loadString(stripslashes($item->orderitem_attribute_names), 'JSON');
                            	$product_options = $registry->toObject();
																						
                            ?>
                            <?php foreach ($product_options as $option) : ?>
							<?php echo JText::_($option->name); ?>: <?php echo Text::_($option->value); ?>
									
									<?php echo '<br />'; ?>
							<?php endforeach; ?>
<?php endforeach; ?>

I do have a question though. This prints out a list of the ‘option’ name : ‘option’ value.

Is there a way to put this information into an array or list so I can then sort and count it?
This goes back to another topic I started, until I found out that the list wasn’t printing out correctly.

Since this is a template and has a front-end and back-end, and tons of code, it is always tricky to
make changes to this kind of project. So, it is hard for someone to help without knowing the entire site.

But, You showed this section:
foreach ($product_options as $option)

Which then prints the option name and value. So, the data is already inside an array $product_options.
So, just before you print it, you can count it and sort it. Counting it should be easy enough with something
like $total_count = count($product_options); Then, display it where you wish to.

Sorting it is tricky. First you must know what is inside of it. You can see it by using this code:
print_r($product_options);
Die("***");
This will just print the array structure with all of the data inside it. So, a simple array would be
printed like array{some data, some data some data} or something similar… But, multidimensional
arrays such as $product_options will have keys such as “name” and “value” and maybe many others.
Inside the printout from the print_r command, you can figure out the structure of the array. Once you
have that, you can create a sort routine to sort the entire array. Depends on which key you want to
sort it by how the code would look. Here is a link to a routine that they put into a function that sorts
this type of array. You do not need it to be a function, just use the sort code changing it to fit your
array once you know the structure.
http://stackoverflow.com/questions/2699086/sort-multi-dimensional-array-by-value
You can sort it into itself by just reassigning the old version to the sorted version. Or, change the
display to use the sorted verison.

Geee, I hope that helps and doesn’t mix you up. Seems to be a bit complicated, but , the code really
isn’t too hard if you know the array’s structure. Good luck and let us know…

Yea it’s a ton of code and I’ve been sorting through it and trying to understand it all. I appreciate the help.

Alright so I printed the array out. The array has 3 keys: “name”, “value”, and “sku”. Which I don’t use the “sku”.

The problem is that it only prints the first item. So as it goes through the for loop each time it seems the array is filled with the information for each item in the order then that prints out.

So is there a way at the end of the loop I can add the contents of $products_options to a new array and it adds to it for all the items in the order?

Then I can take that array and count the items and get rid of the duplicates.

What my goal is is to dump all the information from each item into one array so I can count the duplicates and then print out a list of all the ‘options’ with the quantities.

Alright ignore my last post.

I figured out how to get all the information for the whole order into one array.

I used this code:

<?php $new = array(); ?>
<?php foreach (@$items as $item) : ?>
						
        <?php
                            	
            $registry = new JRegistry;
            $registry->loadString(stripslashes($item->orderitem_attribute_names), 'JSON');
            $product_options = $registry->toObject();
																											
        ?>
		
			<?php $new[] = $product_options; ?>
			
<?php endforeach; ?>

Now my problem is the array is structured weird. (At least to me.)

Array (
[0]
[0]
[name]
[option_sku]
[value]
[1]
[name]
[option_sku]
[value]

[1]
[0]
[name]
[option_sku]
[value]
[1]
[name]
[option_sku]
[value]

[2]
[0]
[name]
[option_sku]
[value]
[1]
[name]
[option_sku]
[value]

[3]
[0]
[name]
[option_sku]
[value]
[1]
[name]
[option_sku]
[value]

[0]
[0]
[name]
[option_sku]
[value]
[4]
[name]
[option_sku]
[value]

)

So I don’t really understand how to sort this array from the link you provided.

I want to sort and count the array by the ‘value’.
So I can eliminate duplicates.

Then I want to print out so it says ‘name’ : ‘value’ - quantity.

Well, do a PRINT_R on array of the actual live data with 3 items in it and post it in the PHP tags.
If it is private info, send it to me in a private message. The text you showed is not the output
of the print_r($new) command and is missing some lines. I will respond very late tonight or in
the morning with a sort routine for you to try. It is just a matter of sorting at the correct level
INSIDE the array. Since this is a multidimensional array, you have to sort from the inside out.

In general it would be something like this… Using $new as the array:
[php]

<?PHP $temp = array(); // Temporary array used to transfer data between arrays $new_sorted = array(); // New sorted version of the array reset($new); // Sets pointer to beginning of $new array no matter where it was foreach ($new as $key => $value) { $temp[$key]=$value["name"]; } asort($temp); foreach ($temp as $key => $value) { $new_sorted[$key] = $new[$key]; } $new=$new_sorted; // Not needed if you just use the $new_sorted instead of $new ?>

[/php]
As you see, this parses thru the array named $new and pulls out the NAME field for each and places
the value of the key and value inside a temporary array. Sorts that array which is not all of the data,
but, just the NAME fields. Then, it writes out a new array of all the data for each of the sorted keys.
You end up with a sorted version. I used the NAME field, but you can change that.

This was not tested, just written quickly for you so you can try it and test it. Let us know if it works for you.

Here is the output of $new:

[php]
Array ( [0] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4’’ Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable (Choose an Option) [option_sku] => [value] => 12/2 (black,white,green) x 25’ L ) [4] => stdClass Object ( [name] => Device (Choose an Option) [option_sku] => [value] => Hubbell 20A SnapConnect Duplex with Connector ) [5] => stdClass Object ( [name] => Device Color (Choose an Option) [option_sku] => [value] => White ) [6] => stdClass Object ( [name] => MC Connector (x2) [option_sku] => [value] => Crouse Hinds 38MCQ ) [7] => stdClass Object ( [name] => 12/2 Anti-Short (x2) [option_sku] => [value] => 12/2 Anti Short ) [8] => stdClass Object ( [name] => 11" Cable Tie (x2) [option_sku] => [value] => 11’’ Cable Tie ) [9] => stdClass Object ( [name] => 4 Port Wago (x3) [option_sku] => [value] => Ideal Model 88 ) [10] => stdClass Object ( [name] => Device Protector Plate [option_sku] => [value] => B-Line BPR1 ) ) [1] => stdClass Object ( [0] => stdClass Object ( [name] => CONDUIT [option_sku] => [value] => EMT ) [1] => stdClass Object ( [name] => DIAMETER [option_sku] => [value] => 3/4’’ ) [2] => stdClass Object ( [name] => Conduit Connector [option_sku] => [value] => Set Screw ) ) [2] => stdClass Object ( [0] => stdClass Object ( [name] => 10’ Stick of EMT [option_sku] => [value] => 3/4’’ ) [1] => stdClass Object ( [name] => Plastic Bang on Bushing [option_sku] => [value] => Plastic Bang on Bushing ) [2] => stdClass Object ( [name] => Assembly/Modification Notes [option_sku] => [value] => This is where i put the notes. ) [3] => stdClass Object ( [name] => Item Delivery Date [option_sku] => [value] => 2014-06-20 ) [4] => stdClass Object ( [name] => Item Delivery Instructions [option_sku] => [value] => This is where i can put notes on the delivery instructions ) ) [3] => stdClass Object ( [0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => T+B SSF-SH2346 ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4’’ Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable (Choose an Option) [option_sku] => [value] => 12/2 (black,white,green) x 25’ L ) [4] => stdClass Object ( [name] => Device (Choose an Option) [option_sku] => [value] => Hubbell 20A SnapConnect Duplex with Connector ) [5] => stdClass Object ( [name] => Device Color (Choose an Option) [option_sku] => [value] => White ) [6] => stdClass Object ( [name] => MC Connector (x2) [option_sku] => [value] => Crouse Hinds 38MCQ ) [7] => stdClass Object ( [name] => 12/2 Anti-Short (x2) [option_sku] => [value] => 12/2 Anti Short ) [8] => stdClass Object ( [name] => 11" Cable Tie (x2) [option_sku] => [value] => 11’’ Cable Tie ) [9] => stdClass Object ( [name] => 4 Port Wago (x3) [option_sku] => [value] => Ideal Model 88 ) [10] => stdClass Object ( [name] => Device Protector Plate [option_sku] => [value] => B-Line BPR1 ) ) [4] => stdClass Object ( [0] => stdClass Object ( [name] => Bracket [option_sku] => [value] => Toe Kick Bracket ) [1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hind TP40DPF ) [2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4’’ Rise Single Gang ) [3] => stdClass Object ( [name] => MC Cable (Choose an Option) [option_sku] => [value] => 12/2 (black,white,green) x 25’ L ) [4] => stdClass Object ( [name] => Device (Choose an Option) [option_sku] => [value] => Hubbell 20A SnapConnect Duplex with Connector ) [5] => stdClass Object ( [name] => Device Color (Choose an Option) [option_sku] => [value] => White ) [6] => stdClass Object ( [name] => MC Connector (x2) [option_sku] => [value] => Crouse Hinds 38MCQ ) [7] => stdClass Object ( [name] => 12/2 Anti-Short (x2) [option_sku] => [value] => 12/2 Anti Short ) [8] => stdClass Object ( [name] => 11" Cable Tie (x2) [option_sku] => [value] => 11’’ Cable Tie ) [9] => stdClass Object ( [name] => 4 Port Wago (x3) [option_sku] => [value] => Ideal Model 88 ) [10] => stdClass Object ( [name] => Device Protector Plate [option_sku] => [value] => B-Line BPR1 ) ) ) [/php]

I tried your code but i couldn’t get it to output the new array.

Well, that is due to the way your array is formatted. If you view it in this manner, you will see better
how it is set up. It is not as simple as we first thought because of the naming conventions and the
way it is laid out. Here is how it looks formatted:
[php]

Array (
[0] => stdClass Object (
[0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 )
[1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF )
[2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4’’ Rise Single Gang )
[3] => stdClass Object ( [name] => MC Cable (Choose an Option) [option_sku] => [value] => 12/2 (black,white,green) x 25’ L )
[4] => stdClass Object ( [name] => Device (Choose an Option) [option_sku] => [value] => Hubbell 20A SnapConnect Duplex with Connector )
[5] => stdClass Object ( [name] => Device Color (Choose an Option) [option_sku] => [value] => White )
[6] => stdClass Object ( [name] => MC Connector (x2) [option_sku] => [value] => Crouse Hinds 38MCQ )
[7] => stdClass Object ( [name] => 12/2 Anti-Short (x2) [option_sku] => [value] => 12/2 Anti Short )
[8] => stdClass Object ( [name] => 11" Cable Tie (x2) [option_sku] => [value] => 11’’ Cable Tie )
[9] => stdClass Object ( [name] => 4 Port Wago (x3) [option_sku] => [value] => Ideal Model 88 )
[10] => stdClass Object ( [name] => Device Protector Plate [option_sku] => [value] => B-Line BPR1 ) )

[1] => stdClass Object ( 
	[0] => stdClass Object ( [name] => CONDUIT [option_sku] => [value] => EMT ) 
	[1] => stdClass Object ( [name] => DIAMETER [option_sku] => [value] => 3/4'' ) 
	[2] => stdClass Object ( [name] => Conduit Connector [option_sku] => [value] => Set Screw ) ) 
	
[2] => stdClass Object ( 
	[0] => stdClass Object ( [name] => 10' Stick of EMT [option_sku] => [value] => 3/4'' ) 
	[1] => stdClass Object ( [name] => Plastic Bang on Bushing [option_sku] => [value] => Plastic Bang on Bushing ) 
	[2] => stdClass Object ( [name] => Assembly/Modification Notes [option_sku] => [value] => This is where i put the notes. ) 
	[3] => stdClass Object ( [name] => Item Delivery Date [option_sku] => [value] => 2014-06-20 ) 
	[4] => stdClass Object ( [name] => Item Delivery Instructions [option_sku] => [value] => This is where i can put notes on the delivery instructions ) )

[3] => stdClass Object ( 
	[0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => T+B SSF-SH2346 ) 
	[1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hinds TP40DPF ) 
	[2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4'' Rise Single Gang ) 
	[3] => stdClass Object ( [name] => MC Cable (Choose an Option) [option_sku] => [value] => 12/2 (black,white,green) x 25' L ) 
	[4] => stdClass Object ( [name] => Device (Choose an Option) [option_sku] => [value] => Hubbell 20A SnapConnect Duplex with Connector ) 
	[5] => stdClass Object ( [name] => Device Color (Choose an Option) [option_sku] => [value] => White ) 
	[6] => stdClass Object ( [name] => MC Connector (x2) [option_sku] => [value] => Crouse Hinds 38MCQ ) 
	[7] => stdClass Object ( [name] => 12/2 Anti-Short (x2) [option_sku] => [value] => 12/2 Anti Short ) 
	[8] => stdClass Object ( [name] => 11" Cable Tie (x2) [option_sku] => [value] => 11'' Cable Tie ) 
	[9] => stdClass Object ( [name] => 4 Port Wago (x3) [option_sku] => [value] => Ideal Model 88 ) 
	[10] => stdClass Object ( [name] => Device Protector Plate [option_sku] => [value] => B-Line BPR1 ) ) 
	
[4] => stdClass Object ( 
	[0] => stdClass Object ( [name] => Bracket [option_sku] => [value] => Toe Kick Bracket ) 
	[1] => stdClass Object ( [name] => BOX [option_sku] => [value] => Crouse Hind TP40DPF ) 
	[2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4'' Rise Single Gang ) 
	[3] => stdClass Object ( [name] => MC Cable (Choose an Option) [option_sku] => [value] => 12/2 (black,white,green) x 25' L ) 
	[4] => stdClass Object ( [name] => Device (Choose an Option) [option_sku] => [value] => Hubbell 20A SnapConnect Duplex with Connector ) 
	[5] => stdClass Object ( [name] => Device Color (Choose an Option) [option_sku] => [value] => White ) 
	[6] => stdClass Object ( [name] => MC Connector (x2) [option_sku] => [value] => Crouse Hinds 38MCQ ) 
	[7] => stdClass Object ( [name] => 12/2 Anti-Short (x2) [option_sku] => [value] => 12/2 Anti Short ) 
	[8] => stdClass Object ( [name] => 11" Cable Tie (x2) [option_sku] => [value] => 11'' Cable Tie ) 
	[9] => stdClass Object ( [name] => 4 Port Wago (x3) [option_sku] => [value] => Ideal Model 88 ) 
	[10] => stdClass Object ( [name] => Device Protector Plate [option_sku] => [value] => B-Line BPR1 ) )
) 

[/php]
So this shows an array in an array in an array. Basically three levels deep. The sort was set for two.

As you see, the above makes it easier to see the layout of it all. You have 5 items in the main array and
each entry has a key of 0 to 10 (some less) and the value is another array of two items. (key & name)
Since your code has inserted so many quotes and double quotes, it is too hard to duplicate this for testing.
But, basically, the first level of decoding name/value or key/value as in the code should grab the top-level
number 0 to 5 which is the items. The value would be the inside array. But, the value is another array of
keys/values. This inside value is the real NAME/VALUE. So, you would have to sort on the inside-inside
value which is the 3rd level, not the 2nd level as the sort was set for.

YIKES! That was a mouthful ! Now, look at the list formatted to be able to read it and tell me what you
want it sorted on. Just a little logic will sort it out! ( Pun-Intended ! )

Alright that seems overly complicated.

What i want to sort it by is ‘value’.

I’ll try to explain what the list is and what I am going for.

The list is basically like a shopping list. The ‘name’ is the product and the ‘value’ is the brand.

So there can be multiple ‘name’ the same but with different ‘value’.

So, what you really have in this array is this:

key (0 to 5 items) value (another array)

 another-array:   key (0 to 10 items)   value (third array)

           third-array:    two entries, NAME and VALUE  ( there are 38 of these total in your sample)

Now, are you talking about sorting all 38 items or still grouping them in the first or second group?

Really not clear on what you want to sort…

Maybe I am not using the correct terminology.

What I am trying to do:

key (0 to 5 items):
The 5 sets in the main array are 5 items that are in an order.

another array (0-10 items):
Each of those has an array that has all the parts to that item.

third array:
Is the name and value of each of those parts

So if you look at the formatted array you posted.

Ex. 1:

In line 7 you have:

[2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4’’ Rise Single Gang )

Then in line 33 you have:

[2] => stdClass Object ( [name] => Mud Ring (Choose an Option) [option_sku] => [value] => 3/4’’ Rise Single Gang )

**These two have the same ‘value’. So I only want to print this out once but show a count of two.

Ex. 2:

In line 5 you have:

[0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => B-Line BB7-16 )

Then in line 31 you have:

[0] => stdClass Object ( [name] => BRACKET [option_sku] => [value] => T+B SSF-SH2346 )

**These two have a different ‘value’. So I want to print both of these out both with and show a quantity of one.

Did I do a better job of explaining it?

Maybe want I want to do is merge the data in the array some how.

Should I go about creating the array $new differently? So its not 3 levels?

Okay, I get it. Thank you for the further explanation! It helps a lot.

I can solve it for you, but, I have to leave for about 5 or 6 hours.
Sorry, but, I will drum up a sort for you when I get back.

You just have to run the first pass totaling and dumping dups. But short on time.

Well, I got delayed a bit time-wise.

So, looking for an easy fix for you on this one. I may have a simple solution.
But, I need to have you test one line for me first.

For some reason I can not dup your array on my test system. Keeps giving me errors…
(Something to do with the characters you are using. 3" for 3 inches? )

Anyway, try this for me. Just after you create the $new() array, right after the end-for-each,
place this line and tell me if it displays a line:
[php]
die($new[3][5][‘value’]);
[/php]
Tell me what it prints out. I think you can sort this by accessing it as one full array. You would
just have to presort it removing the dups. A bit tricky, I think, but, should be able to do it.

it didn’t display anything.

Okay, try:

die($new[3][5][2]);

Nothing printed out with that either.

Just to make sure. I inserted it like this.

[code]

<?php $new = array(); ?> <?php foreach (@$items as $item) : ?>
    <?php
                        	
        $registry = new JRegistry;
        $registry->loadString(stripslashes($item->orderitem_attribute_names), 'JSON');
        $product_options = $registry->toObject();
		
		?>
		
	
				<?php $new[] = $product_options; ?>
<?php endforeach; ?> <?php die($new[3][5][2]); ?>[/code]

Sorry, third array only has two items. (indexes should start at 0, making max as 1 on third index)

I need to understand the layout of the array. Can’t dup it.

So, Try die($new[2][1][1]);

You should get a display of, I think, “Plastic Bang on Bushing”. But, not sure…

Sponsor our Newsletter | Privacy Policy | Terms of Service