Welcome Guest, Not a member yet? Register   Sign In
Help with collating database information
#2

I suspect this might be quite difficult to do with the CI query builder. However you can just write an SQL statement and implement that with the $this->db->query(). (https://www.codeigniter.com/user_guide/d...ml#queries)

If you are using mysql you would do a query on pages, and as a sub query count all the records in the view page table that match the page name. (You should really use a page_id as names can be changed and then the views will not be counted.)

You can read about it here: http://www.mysqltutorial.org/mysql-subquery/ as an example introduction. I am sure there are loads but this was the first google result I found for you.

Another way to do this far more simply is to have a column for page_views_count in the pages table, and every time you log a page view, increment the page count. Then showing page views for all pages would be very easy. Or have a separate table with one row per page, with page summary data in that, like last edited, created by, age, views, etc. Then your CI query would be a simple join to get all the pages and all summary data. Handy for things like most recently edited lists as well as most viewed, least viewed, newest etc.

Hope that helps,

Paul.
Reply


Messages In This Thread
RE: Help with collating database information - by PaulD - 01-14-2017, 08:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB