0

I have an array, that I want to retrieve the values from. When I test the array with a print_r, it says that it has the right values. But when I want to show them in their right places, it says that it has no values.

function employees_items($nodeid, $language)
{
  $query  = db_query(//SOME QUERY);
  $rows   = array();

   foreach ($query as $row) {
    $rows[] = array(
        $row->nid,
        $row->title,
        $row->field_service_nummer_value,
        $row->field_support_email_value,
        $row->uri,
    );
}

    return $rows;   

}

Here I want to retrieve the values...I want the value in $row->uri. The errormessage: Trying to get property of non-object i employees_block_view()

  function employees_block_view($delta = '')
 {
 if (array_key_exists($brandpage_id_page, $medarbejder_brandpages))
    {
     switch ($delta)
    {           

        case 'employees':                                   

        $employees = employees_items($brandpage_id_page, $lang_name);

        foreach ($employees as $row)
            {

              $block['content'] .= '<div class="img">';
              $block['content'] .= '<img style="width: auto; height: 100px;"    src="'.file_create_url($row->uri). '" alt="Vores support medarbejder" />';
   }
  return $block;
 }
1
  • This question appears to be off-topic because it has been cross-posted on Stack Overflow. Please post your question to one site in the network only.
    – Clive
    Sep 15, 2014 at 11:59

1 Answer 1

-1

Try $row['uri'] instead. As 'uri' is merely the key and not another object.

In this line of code:

$block['content'] .= '<img style="width: auto; height: 100px;" src="'.file_create_url($row->uri). '" alt="Vores support medarbejder" />';

you refer to another object, the uri ($row->uri). Within the $row array, that you printed with print_r, there is the key 'uri'. To get the value of that key you should use $row['uri'].

3
  • can you please elaborate it; try to add some description. Sep 15, 2014 at 9:54
  • In this line $block['content'] .= '<img style="width: auto; height: 100px;" src="'.file_create_url($row->uri). '" alt="Vores support medarbejder" />'; you refer to another object, the uri ($row->uri). Within the $row array, that you printed with print_r, there is the key 'uri'. To get the value of that key you should use $row['uri'].
    – jojomojo
    Sep 15, 2014 at 10:01
  • Please edit you answer and add your description. BTW I didn't ask that for me ;) Sep 15, 2014 at 10:03

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