By AndrewJarvis on
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
Oh for goodness' sake
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
To show you what I'm dealing
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?
put this in a page, enable
put this in a page, enable the php filter, and hit preview:
Just change the node_load() to the number of your CCK node, and you will know everything that you need to.
- Corey
Yes
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')
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/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
OMG, that is EXTREEMLY helpful!
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];
WOOOOOOHOOOOOOOOOOOOOO! I
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];
Okay, now I am using this
Okay, now I am using this code in my Views Theme File:
========================================================
========================================================
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?
Got it
Got it :)
http://www.used-computers-dc.com/servers