Calling Library From View. Possible?

#1
[eluser]Deep Arora[/eluser]
Is it possible to load and call a function from a custom written library in a VIEW? The problem I am facing is that I populate a recordset with blog categories, then while displaying the categories in frontend, I need display the total posts in the blog categories. So I need to run a query to get total posts of that particular category while traversing the records in the recordset in view.

Or is there a better way of handling this?

#2
[eluser]Dam1an[/eluser]
You should try to avoid making database calls from your views, and yes there is a better way Smile
The following is some code from one of my projects, which will give you what you want, but not using blogs and categories, instead it uses hotels and facilities, but I'm sure you can figure out how to make it fit your needs

Code:
SELECT COUNT(`facility_id`) AS `count`, `facilities`.`name` FROM `hotel_facilities` JOIN facilities ON hotel_facilities.facility_id = facilities.id GROUP BY `facility_id`

And in my case, that gives me
Quote:Parking: 65457
Restaurant: 46422
Pets Allowed: 39147
Room Service: 29456
Meeting/Banquet Facilities: 32592
Bar: 49149
...

If you try to get this to work and can;t just post back what you've tried along with your schema, and I'll try be more to the point Smile

#3
[eluser]Deep Arora[/eluser]
Thanks mate..but it doesn't work for all the cases that I have.

Let me put another case: Creating Category Tree. How can I show a nested category tree with main categories and child categories? I have been struggling to do this but couldn't figure out yet.

You/someone else has a solution for this? Any code?

#4
[eluser]Dam1an[/eluser]
Ah, nested hierachies in SQL, something which I don't really come accorss, so never had to spend too much time worrying about it, butif you search the forums for MPTT and read this (there's a similar article on the MySQL site somewhere too) you should be heading in the right direction


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.