Hello peoples of Drupal !

As a drupal beginner, I have been working on a rather simple module. And after a few hour of research i could not find any answers to my problem on the web.
Basically right now i simply want to show[programmatically] some fields related to nodes i created.

I have a few nodes (products) and i want to render a few fields from these nodes ( retail price, image, title and serie), simple enough. i want to know how can i render multiple fields (from a given node) using field_get_items (or any other efficient method).

here is a piece of my code:

function test{

$query = ... ;
$result = db_query($query);

 foreach ($result as $record) {
        $nid = $record->nid;
        $node = node_load($nid);    
        $field = field_get_items('node', $node, 'field_serie');
        $output[$record->nid] = field_view_value('node', $node, 'field_serie' , $field[0]);

return $output;

So right now this piece of code allows me only to see the value of the 'serie' field how do i add the other fields that i want ?


Jaypan’s picture

You've told us how you are trying to achieve some goal, but have not told us what that goal is.

Specializing in Drupal 8 upgrades. Checkout my Japan podcasts and my Drupal presentations on YouTube
Atmaelius’s picture

I'm trying to make an ordered list of nodes [in the form of a table], every item of the list will show the few fields i have mentionned.
I'ts a price list module actually, i want to make some kind of table that will show the informations i want in order to be able to quickly check the needed informations of a product.

Visually, something like below, as i explained before my problem comes at the point where i want to get the actual data from the nodes inside these fields.

          <td>[Node#1] Product Image Here</td>  
          <td> Product Name and link to full node content</td> 
          <td> Table field containing prices by qty [read only]</td> 
          <td>  Second table field containing price by qty [content can be modified]</td>
    <tr> [Node#2]</tr>
    <tr> [Node#3]</tr>
    <tr> ... </tr>

Atmaelius’s picture

Allright i found a way to do what i wanted, not quite sure it's the most efficient way but its works for me.

i simply used multiple field_get_items and concatenated pieces of my array containing the data inside $output value like this :

    $result = db_query($query);
    $output .= "<table>";

    foreach ($result as $record) {
        $nid = $record->nid;
        $node = node_load($nid);
        $title_value = $node->title;
        $serie_value = field_get_items('node', $node, 'field_serie');
        $price_table_value = field_get_items('node', $node, 'field_retail_price_table');
        $image = field_get_items('node', $node, 'field_image');

        $output .= "<tr>";
        $output .= '<td>' . drupal_render($image) . '</td>';
        $output .= '<td> <a href="content/' . strtolower($title_value).  '">' . $title_value . '</td>';
        $output .= "<td>" . $serie_value . "</td>";
        $output .= "<td>" . $price_table_value . "</td>";
        $output .= "<td>" .'coming soon !'. "</td>";
        $output .="</tr>";
    $output .= "</table>";

    return $output;

Still have to figure out how to get the image of the product to show, and the table field (https://drupal.org/project/tablefield)

Atmaelius’s picture

I think this topic can be closed, i've been solving my problems one by one, this topic is no longer necessary.