Could someone tell me how, or direct me to a tutorial that explains how to do a query that asks Drupal for all the variables (or just the fields I want) of a node? I’m using this in the middle of a view template by the way, and In case you're wondering (or in case it helps) this is for a custom CCK image_attach field's image file name.

Comments

AndrewJarvis’s picture

I always look like an idiot because we can't edit our own posts, lol. Query misspelled and "all of a node's the viarables?" haha

AndrewJarvis’s picture

To show you what I'm dealing wiht, I just want to get this variable... I've got it on the node page, but not the views page...

You can see that here in my content template I added print_r($node) at the top, and it shows me all the variables, including the file name http://used-computers-dc.com/thinkpad-570e-p3-500mhz-slimline-w-usb-cd-rom

(towards the middle of the page you'lll find [field_photo] => Array
(
[0] => Array
(
[fid] => 1
[title] => TP600600ETP570.jpg

But on the view, I print_r($node) and as you can see, I don't have that variable in the array http://used-computers-dc.com/desktops - so how do I query Drupal for the variable directly?

coreyp_1’s picture

put this in a page, enable the php filter, and hit preview:


$node = node_load(1);
echo "<pre>".print_r($node, true)."</pre>";

Just change the node_load() to the number of your CCK node, and you will know everything that you need to.

- Corey

dman’s picture

In a views context, the $node is naturally incomplete, and only contains the fields you asked for (for database query reasons).
node_load() will fill out the rest - although that will of course totally attack the database savings that views just made.

The compromise is probably to find which call adds the fields you really need to the node, and call that explicitly. EG, if you want the upload-attached files, but they are not there in your view, call hook_nodeapi($node, 'load')

    if ($extra = upload_nodeapi($node, 'load', FALSE)) {
      foreach ($extra as $key => $value) {
        $node->$key = $value;
      }
    }

or something. Messy looking, but maybe better mojo than everything, all the time.

Also, try installing the devel.module which provides full detailed node object dumps for you to inspect.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

AndrewJarvis’s picture

Thank you thank you thank you!

I am SO CLOSE now, I just need to spit it out correctly from the array - here are the strings i've tried that didn't work:

echo $node->field_phot->filename;
echo $node->filename;
echo $node[filename];

AndrewJarvis’s picture

WOOOOOOHOOOOOOOOOOOOOO! I GOT IT!

http://www.used-computers-dc.com/desktops

look at that little guy, isn't he beautiful? hahahah

I'm sure a few days (or even hours from now) that page will look completly different, so for those of you who aren't looking at it now, i will tell you, it's just a page with x305.jpg in the middle! haha

this was the string:

echo $node->field_photo[0][filename];

AndrewJarvis’s picture

Okay, now I am using this code in my Views Theme File:

========================================================

if ($count == 0) echo "<table cellspacing='2' cellpadding='10' border='2' align='center' bgcolor='505050'><tr>";

echo "
<td bgcolor='303030' align='left'>";


$node = node_load($count);
echo $node->field_photo[0][filename];
echo "<br /> <br />";
echo $i;

echo "</td>";

if (($count+1) % 1 == 0) echo "</tr><tr>";

if ($count == ($view->total_rows -1)) echo "</tr></table>";

========================================================

But node_load($count) only serves to be the node idea of the number of cycles through it's gone, and not the ACTUAL NODE IDEA FOR THAT CYCLE.... is there some variable that's been passed from the template.php file that i can use as the NID?

AndrewJarvis’s picture