Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7713055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:46:30+00:00 2026-06-01T01:46:30+00:00

Within CodeIgniter, I’m doing a select, retrieving some blogposts. But I also want the

  • 0

Within CodeIgniter, I’m doing a select, retrieving some blogposts. But I also want the total reactions of a blogpost with the count() function. But when I’m doing this, it only returns one record.

Example:

    $this->db->select('idee_id, titel, omschrijving, type, top_idee, tbl_users.foto as user_foto');
    $this->db->from('tbl_idee');
    $this->db->join('tbl_types', 'tbl_idee.type_id = tbl_types.type_id');
    $this->db->join('tbl_users', 'tbl_idee.user_id = tbl_users.user_id');
    $this->db->join('tbl_comments', 'tbl_users.user_id = tbl_comments.user_id');
    $this->db->order_by('post_datum', 'DESC');
    $this->db->limit(10);
    $q = $this->db->get();

Now I only get the blogposts without total reactions of one blogpost.
How can I fix this? With a select in a select.?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:46:31+00:00Added an answer on June 1, 2026 at 1:46 am

    First you need to make the database select the number of each blog post’s comments

    $this->db->select('idee_id, titel, omschrijving, type, top_idee,
          tbl_users.foto as user_foto, COUNT(*) AS comments',FALSE);
    

    note the second parameter, it prevents codeigniter from parsing the COUNT() function

    you are retrieving data from a blog post together with its comments, so you need to GROUP BY the data which makes a blogpost unique:

    $this->db->group_by('idee_id,titel, omschrijving, type,
          top_idee, tbl_users.foto');
    

    the rest of your query should be correct

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using MySQL ActiveRecord with CodeIgniter to submit queries, but have run into some
Within my CodeIgniter app, I'm using a Jquery calendar pop-up that also captures time
It used to be that within a CodeIgniter model you couldn't access another model.
I've recently started logging my errors through codeIgniter. Since doing so, I have noticed
I have two directories within my codeigniter controller. /controllers/admin/ dashboard.php content.php enquiries.php /controllers/members/ profile.php
I am trying to edit my config/database.php within my CodeIgniter project so that I
I am using codeigniter and its routes system successfully with some lovely regexp, however
I have enabled the inbuilt logging within Codeigniter. This works fine. However I'm running
Did anybody tried to integrate HybridAuth within CodeIgniter ?
Im trying to learn how to use JSON from within codeigniter. I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.