1

I tried using below code in Views > Global PHP field.

<?php

$request = db_query("SELECT data FROM {uc_order_products } WHERE order_id= $row->order_id")->fetchField();
$att =  $request;

$data = unserialize($att);

if (is_array($data['attributes'])) {
  foreach ($data['attributes'] as $attribute => $option) {
    echo $attribute . ':   ' . implode(', ', (array)$option) . '<br>';
  }
}

?>

Adding above code I get the below error :

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Also how do I print each attribute in a different field?

2 Answers 2

0
<?php

$request = db_query("SELECT data FROM {uc_order_products } WHERE order_id= $row->order_id");
foreach($request as $rwq){
$att =  $rwq;

$data = unserialize($att);

if (is_array($data['attributes'])) {
  foreach ($data['attributes'] as $attribute => $option) {
    echo $attribute . ':   ' . implode(', ', (array)$option) . '<br>';
  }
}
}
?>

try this

0

If you use a variable in your request, it's preferable to use it like this : WHERE o.order_id = :oid', array(':oid' => $row->order_id).

So I guess it would be :

$request = db_query('SELECT o.data FROM {uc_order_products} o WHERE o.order_id= :oid', array(':oid' => $row->order_id)')->fetchField();

To have different fields, you can do this processus for each field, by using multiple PhP fields in your view. But to rationalize requests, I would first do that request in the "setup code" and set all your data in the $static variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.