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

  • SEARCH
  • Home
  • 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 7194807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:26:58+00:00 2026-05-28T20:26:58+00:00

I am using codeigniter 2 in my project and I have a problem that

  • 0

I am using codeigniter 2 in my project and I have a problem that I hope that you’ll help me in solving it.

I have two mysql tables,”authors” and “articles” where relation is as “one author to many articles”. I need to get authors “from ‘authors‘” that have already active articles in “articles“.

note that in articles table, I have column called “status_id” that set to 1 if the article is active or 0 if suspended. and I have in “authors” table a record called “authors_categories_id”.

I tried to do it with this code

$this->db->select('authors.name,authors.about,authors.author_thumbnail,authors.authors_categories_id,authors.user_id,authors.status_id,authors.id AS auth_id')
                  ->from('authors')
                  ->join('articles', 'authors.id = articles.author_id')
                  ->where('authors.authors_categories_id',$AuthCategory)
                  ->where('articles.status_id', 1)
                  ->order_by("auth_id", "desc")
                  ->limit($limit, $start);
            $Res = $this->db->get();
            $data['Authors'] = array();
            foreach($Res->result() as $R)
            {
                $data['Authors'][] = $R;
            }
            print_r($data['Authors']);

My problem that the code results me duplicated authors. for example, if an author have 5 articles in ‘articles’ table, the result will be 5 records for the same author while i need to view each author just once not more.

I need the code to generate records according to count of authors not articles.

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-05-28T20:26:59+00:00Added an answer on May 28, 2026 at 8:26 pm

    add DISTINCT in your query.

    select('authors.name,authors.about,authors.author_thumbnail,authors.authors_categories_id,authors.user_id,authors.status_id,authors.id AS auth_id')
                  ->from('authors')
                  ->join('articles', 'authors.id = articles.author_id')
                  ->where('authors.authors_categories_id',$AuthCategory)
                  ->where('articles.status_id', 1)
                  ->group_by('authors.name');
                  ->order_by("auth_id", "desc")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using CodeIgniter with CodeIgniter sessions that are stored in a MySQL database. I
i am using codeigniter 2.1.0 and mysql database. in my admin panel i have
I have a project that I am developing built off CodeIgniter. The main part
I started using codeigniter for my project. I have user authentication system for my
I've been working on a home project using CodeIgniter Reactor, and have come to
I have a PHP project (I'm using CodeIgniter) with data capture. The form is
I am using CodeIgniter 2.1.0 and MySQL database. I have uploaded an image through
I'm using codeigniter for this project. I have a search form and search form
I'm using codeigniter and the project i'm working on has to be in two
I am using Codeigniter to build my project. Here i have some doubts or

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.