drupal-6


How do I get the results of a view and store them in a php var?


I have a custom view that I set up in drupal. What I would like to do is make a function call of some kind, and then assign the results to a php variable. I would like the contents of the view (as opposed to the results of a view export) in this new variable. Is this feasible? If it is a function call, I would appreciate a small example too. Thanks!
I haven't done too much hacking around in views, but it looks like maybe views_embed_view() might be what you are looking for. I found a good overview of the views API here: http://www.trellon.com/content/blog/view-views-api
You can get the view object with function views_get_view($view_name).
If what you mean by contents of the view is the view object itself you'll need simply:
$view = views_get_view('name_of_the_view');
However, if you mean the data returned by your view you'll need a little bit more.
$results = views_get_view_result('name_of_the_view', 'display_id');
At last, if you wish to have more control you can try another approach, creating the view object and working on it afterwards.
//variables for your view, display and resulting array
$my_view_name = 'yourview';
$my_display_name = 'yourdisplay';
$my_arguments = array();
//Creating the view object and configuring it
$view = views_get_view($my_view_name);
if ($my_arguments){
$view->set_arguments($my_arguments);
}
$view->get_total_rows = True;
$view->set_items_per_page(0);
$view->build($my_display_name);
$view->execute($my_display_name);
//now you have your data array
$view_results_array = $view->result;

Related Links

Cannot login to Drupal website
password reset link not working in drupal 6
Theme_image() returns nothing
Issues in node template naming in drupal 6
Sort Content in drupal 6 views using date and time seperate fields
Issues with custom queries in views
Lot of spams on drupal 6 site with reCaptcha module [closed]
get data from just created node and pass it to url
how to a translatable string in drupal theme?
How to create node of particular content type from webform results?
Need to export drupal comments to disqus
How to add js file in footer in drupal6?
how to include jwplayer in drupal site
Is it possible to combine two hook_preprocess functions into one in drupal 6
How to access cck fields in tpl file?
drupal 6 authenticated user

Categories

HOME
arduino-uno
webpack
magnific-popup
tizen
ngrx
appx
view
office365api
sd-card
alfresco
read-eval-print-loop
youtube-dl
binary-tree
callback
alpha
ojdbc
wamp
append
contact
add
gorm
adobe-analytics
dynamics-crm-online
iolanguage
django-simple-history
highlight.js
serilog
pugjs
abi
sox
core-text
zurb-foundation-6
jndi
android-widget
buildbot
facet
chromebook
gitignore
file-rename
functor
data-manipulation
calibre
accelerate-framework
revolution-slider
restlet
disassembling
web-mining
multilingual
starteam
leading-zero
glew
fakeiteasy
businessworks
promela
brightcove
jxcore
pg-dump
zendesk-app
gcsfuse
sqldf
imanage
lync-client-sdk
cubes
xcb
visual-c++-2008
vmware-tools
slicknav
database-optimization
gstreamer-0.10
ipconfig
goose
phpcas
hsv
endeca-workbench
metaclass
atk4
0xdbe
ionic
splash
key-management
bigbluebutton
google-style-guide
winddk
onactivityresult
phpthumb
wp-query
rebol3
transcoding
imdbpy
flexmojos
quantlib-swig
batterylevel
dataadapter
mqx
http-unit
cisco-jtapi
jquery-ui-layout
calling-convention
disclosure
w3wp.exe
perfect-hash
sef
iweb
data-driven
thread-local-storage
putchar
zune

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App