views:

471

answers:

2

I have a View set to grab the latest forum posts. That's working fine, but I'd like to limit it to get the last 5 records only. I know I can display only 5 with PHP but I don't want a larger query than I need. I can't find any option for this in the View.

thanks

A: 

Yep. There is an option that limits it called 'Items to display:' under Basic Settings.

Kevin
Thanks Kevin. I see an option called "Items per page". I see what it's doing now. After I set"Use Pager" to "No", then it changes "Items per page" to "Items to display". But when I preview the query it creates, I don't see a LIMIT in there, which tells me that it's getting all the rows in the table. Is this a limitation of queries in the View?
EricP
That I am not sure of. You could use PHP with the Views hook _views_pre_execute and modify the $view->build_info['query'] and append LIMIT 5 near the end. Not elegant but if you're looking for performance, that's one way. Views has so much going on internally though, you may want to dig in and see what Items to Display affects.
Kevin
The query preview in Views is not the final query that's sent to the database engine. The final query includes a LIMIT already, which you can see by turning on query log in the devel module.More general advice: few people can write better queries than Views writes automatically. If you're one of those people, you probably shouldn't be using Views. And if you're not, you should just let Views write the queries and stop worrying about the details.
Scott Reynen
That's pretty much what I thought but didn't have time to bust out devel and dig in. Otherwise that option wouldn't be so useful.
Kevin
Thank you. That's good to know.
EricP
A: 


##

vg fg

related questions