Try changing this to this to see what the properties really are. If you don't understand what you get there, then tell me the results, and I'll try and interpret them for you.
$orderattributes = print_r($row,1); print $orderattributes;
________________________________
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Shai Gluskin Sent: Thursday, September 02, 2010 2:01 PM To: support@drupal.org Subject: Re: [support] Unserializing Data for Use in a View
David and all,
David, thanks for the response:
I just tried
$orderattributes = $row->{$field->data}; print $orderattributes;
I get a php fatal error: "Cannot access empty property"
The following is from Views "Theme information": Field uc_order_products: data (ID: data)
Ideas?
Thanks much,
Shai
On Thu, Sep 2, 2010 at 4:31 PM, Metzler, David metzlerd@evergreen.edu wrote:
I'm not an expert here, but I'm reading the coments differently than you are. I think you should be working with $row->data ( or at least $row) and not with $output. That's got html in it, right? Dave
________________________________
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Shai Gluskin Sent: Thursday, September 02, 2010 1:24 PM To: support@drupal.org Subject: [support] Unserializing Data for Use in a View I'm creating a view of ubercart order products. I got the necessary data to be accessible to Views using Table Wizard (http://drupal.org/project/tw).
The product attribute info is stored serialized in the "data" field on the uc_order_products table. Here is an example of the raw serialized data:
a:5:{s:6:"kit_id";s:3:"570";s:6:"module";s:14:"uc_product_kit";s:10:"att ributes";a:2:{s:9:"Attending";a:1:{i:0;s:26:"Jane Doe, John Doe";}s:4:"Note";a:1:{i:0;s:45:"We are friends of Eric Smith and Sandy Smith";}}s:9:"shippable";s:1:"0";s:9:"unique_id";s:23:"4c7d632a8090c7.95 333579";}
I have no problem printing it out like above.
Unserialized it looks like this:
Array ( [kit_id] => 570 [module] => uc_product_kit [attributes] => Array ( [Attending] => Array ( [0] => Jane Doe, John Doe ) [Note] => Array ( [0] => We are friends of Eric Smith and Sandy Smith ) ) [shippable] => 0 [unique_id] => 4c7d632a8090c7.95333579 ) I want to print out: Jane Doe, John Doe Here is what views-view-field.tpl.php has to say: // $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $ /** * This template is used to print a single field in a view. It is not * actually used in default Views, as this is registered as a theme * function which has better performance. For single overrides, the * template is perfectly okay. * * Variables available: * - $view: The view object * - $field: The field handler object that can process the input * - $row: The raw SQL result that can be used * - $output: The processed output that will normally be used. * * When fetching output from the $row, this construct should be used: * $data = $row->{$field->field_alias} * * The above will guarantee that you'll always get the correct data, * regardless of any changes in the aliasing that might happen if * the view is modified. */ This is what I'm putting in views-view-field.tpl.php: $data = unserialize($output); print $data['Attending'][0];
Nothing gets returned.
What am I doing wrong?
thanks,
Shai
-- [ Drupal support list | http://lists.drupal.org/ ]