I want to render an array and print the output as Block[content]. There is either my Foreach or the way I use $item array or $row that is wrong. I will appreciate your help.
The result i get is the HTML I define in Block[content] without the values of $row->uri, $row->title, $row->body_value. They are empty. And it means I have done something wrong.
function produkt_block_view($delta = '')
{
$block = array();
$list = produkt_produkliste(1);
$items = array();
foreach ($list as $row) {
$items[1] = $row->uri;
$items[2] = $row->title;
$items[3] = $row->body_value;
}
switch($delta) {
case 'produkt' :
$block['content'] = '<a href="/19">';
$block['content'] .= '<img class="pimg" src="'.$row->uri.'" alt="Se alle vores filter elementer her">';
$block['content'] .= '<p class="pname">"'.$row->title.'"</p>';
$block['content'] .= '<p>"'.$row->body_value.'"</p>';
$block['content'] .= theme ('item_list',array('items' => $items, 'type' => 'ol', 'attribute' => 'produkt'));
break;
}
return $block;
}
And I ended with this solution that get some results.
function produkt_block_view($delta = '')
{
$query = db_query("SELECT node.title, field_data_field_kortbeskrivelse.field_kortbeskrivelse_value, file_managed.uri
FROM node
JOIN field_data_field_tilh_rsforhold ON
node.nid = field_data_field_tilh_rsforhold.entity_id
JOIN field_data_field_kortbeskrivelse ON
node.nid = field_data_field_kortbeskrivelse.entity_id
JOIN field_data_field_billede ON
node.nid = field_data_field_billede.entity_id
JOIN file_managed
ON field_data_field_billede.field_billede_fid = file_managed.fid
WHERE field_data_field_tilh_rsforhold.field_tilh_rsforhold_target_id = 30
AND field_data_field_billede.bundle = 'produkt_kategori'
"
);
$rows = array();
foreach ($query as $row)
{
$rows[] = array(
$row->title,
$row->field_kortbeskrivelse_value,
$row->uri
);
print_r($row->uri);
$block['content'] = '<a href="' . url(19) . '"><img class="pimg" src=/"'. $row->uri . '" alt="Se alle vores filter elementer her" /></a>'; // assuming that anchor tag will wrap img
$block['content'] .= '<p class="pname">' . $row->title . '</p>';
$block['content'] .= '<p>' . $row->field_kortbeskrivelse_value . '</p>';
$block['content'] .= theme ('item_list',array('type' => 'ol', 'attribute' => 'produkt'));
}
return $block;
}