[support] Unserializing Data for Use in a View

Shai Gluskin shai at content2zero.com
Fri Sep 3 01:20:13 UTC 2010


Hi Dave and all,

Thanks so much. I figured it out.

Here is the answer:

$data = unserialize($row->{$field->field_alias});
print $data[attributes][Attending][0];

Here was one prior step prior that made things easy:

$data = unserialize($row->{$field->field_alias});
echo '<pre>';
print_r ($data);
echo '</pre>';

But as someone who is fairly new to programming... and I'm basically a
site-builder, I code on an as-needed basis... not all day long -- let me
just rant about something in coding documentation that drives me nuts! There
are no conventions when presenting examples about what is literal and what I
should fill in with an item specific to my situation. I can't tell you how
many other things I tried before I finally saw an example of
"$row->{$field->field_alias}
being used and AHA --- It's literal, I copy as is; I'm not supposed to
change anything. I think this is the biggest challenge to people learning
programming.

Dave thanks SOOOO much, you really helped.

Shai

On Thu, Sep 2, 2010 at 7:46 PM, Shai Gluskin <shai at content2zero.com> wrote:

> Hi Dave,
>
> Thanks so much, this is what prints out, following your instructions. the
> yellow part is the part that I'm interested in:
>
> stdClass Object ( [order_product_id] => 65 [uc_order_products_qty] => 2
> [uc_order_products_title] => Rosh Hashanah Day 1
> [uc_orders_billing_last_name] => Eizen [uc_order_products_data] =>
> a:5:{s:6:"kit_id";s:3:"570";s:6:"module";s:14:"uc_product_kit";s:10:"attributes";a:2:{s:9:"Attending";a:1:{i:0;s:26:"Irene
> Eizen, Bernard Eizen";}s:4:"Note";a:1:{i:0;s:45:"We are friends of Eric Sack
> and Sandy
> Steiker";}}s:9:"shippable";s:1:"0";s:9:"unique_id";s:23:"4c7d632a8090c7.95333579";}
> [uc_order_products_nid] => 565 )
>
> Shai
>
> On Thu, Sep 2, 2010 at 7:22 PM, Metzler, David <metzlerd at evergreen.edu>wrote:
>
>>  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 at drupal.org [mailto:support-bounces at drupal.org] *On
>> Behalf Of *Shai Gluskin
>> *Sent:* Thursday, September 02, 2010 2:01 PM
>> *To:* support at 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 at 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 at drupal.org [mailto:support-bounces at drupal.org] *On
>>> Behalf Of *Shai Gluskin
>>> *Sent:* Thursday, September 02, 2010 1:24 PM
>>> *To:* support at 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:"attributes";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.95333579";}
>>>
>>>
>>> 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/ ]
>>>
>>
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20100902/28a4bca8/attachment-0001.html 


More information about the support mailing list