Trying to output the results of a query to a view and I can't seem to get the pager function to work. I have tried to use both views_theme() and views_build_view.
Background
I have two nodes, Company and Program joined by a Node Reference (Company Name). One company has many programs. I am running a query:
$sql ="SELECT *
FROM `content_type_programs`
Where $where_clause_final
Group by field_program_name_value" ;
then I pass the results to items array:
$items = array();
while ($item = db_fetch_object($query_result)) {
$items[] = $item;
}
Then I am outputting the view:
$view = views_get_view('cost2');
$view->build_type = 'page';
$view->type = 'page';
$view->num_rows = 3;
$view->use_pager;
$view->limit = 2;
views_sanitize_view($view);
return views_theme('views_view', $view, 'block', $items, NULL, array());
I get the desired results BUT I can't seem to get the pager function in the view to work, I always get all the results on one page.
I also tried:
print (views_build_view('embed', $view1, $current_view->args, false, false)); and wrapped this inside the db_fetch_object() loop.
Here is an export of my view:
$view = new stdClass();
$view->name = 'cost2';
$view->description = 'List a Gap Year Company with its corresponding programs';
$view->access = array (
0 => '1',
1 => '2',
2 => '3',
);
$view->view_args_php = '';
$view->page = FALSE;
$view->page_title = 'Gap Company and it\'s Programs';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = 'Sorry, no results found.';
$view->page_empty_format = '1';
$view->page_type = 'teaser';
$view->url = 'cost3';
$view->use_pager = TRUE;
$view->nodes_per_page = '5';
$view->sort = array (
);
$view->argument = array (
array (
'type' => 'nid',
'argdefault' => '1',
'title' => '',
'options' => '0',
'wildcard' => '',
'wildcard_substitution' => '',
),
);
$view->field = array (
);
$view->filter = array (
array (
'tablename' => 'node_data_field_company_name',
'field' => 'field_company_name_value_like',
'operator' => 'word',
'options' => '',
'value' => '',
),
);
$view->exposed_filter = array (
array (
'tablename' => 'node_data_field_company_name',
'field' => 'field_company_name_value_like',
'label' => '',
'optional' => '0',
'is_default' => '0',
'operator' => '0',
'single' => '0',
),
);
$view->requires = array(node_data_field_company_name);
$views[$view->name] = $view;
I have played around with the view, and the functions views_theme() and views_build_view() for hours but to no avail. Any help would be appreciated. I may be forced to write my own pager in the query if I can't get it to work. Wonder if it has anything to do with the tables being joined by a Node Reference ?????
Comments
Comment #1
merlinofchaos commentedI don't understand how you got as far as you did without figuring this out. I mean, really, you shouldn't be doing what you're doing. But you are. I have no interest in supporting this; Views was never meant to be used as just the theming portion, but I recommend you look up 'pager_query' on api.drupal.org -- that should be enough to solve all of your problems.
Comment #2
ThaboGoodDogs commentedThanks for getting back to me. My aim was to create a relational database using nodes. Basically do a query then pass the results (Node ID) to a view using the "Arguments" section of the views module. Ok so my code sucks and I'm not looking for someone to wipe my botty here but can you point me to a tutorial or two. I also don't understand what you mean by "Views was never meant to be used as just the theming portion".
Regards
Richard
MyLittlePortal.com
Comment #3
merlinofchaos commentedIt means just what it says it was; it wasn't meant for you to run an arbitrary query and then try to get Views to theme it.