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

How to pull all emails of the site members in og invite new members?
drupal, tree in search form
how to enter words in synonyms.txt file of apache solr search
How to disable/hide the submit function when the form is submitted?
Heirarchical Select Steps Drupal 6
Making views custom field sortable in Drupal on a table view?
Drupal6 - product comparison
drupal 6 multitab with ajax content
How to place a cck field inside a fieldset?
How to display the maxlength countdown remaining characters for custom form fields
How to put the field label inside the form select field?
Symbol “?” in alias or Dirty url
hook_comment not modifying data
How to use php session in drupal 6
Drupal 6, Create a form in a node which save data to another content type (cck)
Synchronize language switcher with language from user profile

Categories

HOME
pandas
wso2-am
deployment
heroku
path-finding
layout
stock
raspberry-pi
objectgears
v8
ebean
onelogin
cross-validation
fancybox-3
modelica
qt-creator
alignment
usergrid
gz
highlight.js
finite-automata
database-replication
contextmenu
alpine
visjs
jasonette
accessor
devops
poltergeist
virtualdub
assistant
replaceall
newline
directx-10
bosh
key-value-observing
xquery-3.0
ghost4j
google-api-nodejs-client
git-merge
restlet
hot-module-replacement
multilingual
swift3.0.2
c11
cookiecutter-django
android-tabhost
reportingservices-2005
elmah
powershell-dsc
nxlog
acoustics
reactive-cocoa-5
sas-jmp
rainbowtable
appcompat
hendrix
integrity
nodebb
android-cursor
pillow
sqldf
mcafee
bind9
angular-strap
static-ip-address
angular-cache
heidisql
mikroc
plottable.js
fputcsv
testng-dataprovider
rvest
energy
metaclass
comobject
qdialog
django-unittest
riak-cs
event-bubbling
xojo
android-radiobutton
dml
funcunit
mechanize-ruby
dealloc
dotnetnuke-5
clipper
libstdc++
cisco-jtapi
coderush
broken-links
objective-c-2.0
netbeans-6.9
php-parser
xmemcached
ecl
floating
google-friend-connect
.nettiers
jquery-ui-droppable
xsdobjectgen
nsviewanimation
perfect-hash
user-friendly
iweb
microsoft-virtualization
javap
mdac
3gp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App