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 6358293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:20:41+00:00 2026-05-24T23:20:41+00:00

Am creating a web app in codeigniter, it retrieves posts from the database for

  • 0

Am creating a web app in codeigniter, it retrieves posts from the database for a user based on the keywords they have added to their keyword list.
Am trying to retrieve all the posts with the users keywords but,it returns only one post whereas there are mutliple matches for the keywords in the posts

This is are the functions from my model

This function retrieves the users keywords

function user_keywords($user_id) {
         //Get all the user keywords
         $q = $this->db->select('keywords')
                        ->from('keywords')
                        ->where('U_id',$user_id)
                        ->get();
        $words = $q->result_array();
        return $words;
     }

This function retrieves the posts

function get_latest_pheeds() {
        $this->load->helper('date');
         $time = time();
         $keyword = $this->user_keywords($this->ion_auth->user_id);
         foreach($keyword as $word) {
         $q = $this->db->select('user_id,pheed_id,datetime,pheed,COUNT(pheed_comments.comment_id) as comments')
         ->from('pheeds')
         ->join('pheed_comments','pheed_comments.P_id=pheeds.pheed_id','left')
         ->like('pheed',$word['keywords'])
         ->order_by('datetime','desc')
         ->get();
         }
         $rows = $q->result_array();
         return $rows;
     }

And my controller encodes it in JSON

function latest_pheeds() {
            if($this->isLogged() == true) {
            $this->load->model('pheed_model');
            $data = $this->pheed_model->get_latest_pheeds();
            echo json_encode($data);
            }
            return false;
    }

I really appreciate the help

  • 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-24T23:20:43+00:00Added an answer on May 24, 2026 at 11:20 pm

    I think (but it is hard without testing) that the problem comes form the function get_last_feeds :

    you query is built over each loop’s iteration, but you fetch the results after. I think you get the results only for the last query (if you don’t fetch the results on each loop, the next iteration overwrites the original request without fetching it’s results).

    I would make something like this :

    <?php
    function get_latest_pheeds() {
         $rows = array(); // The final result, an array of rows
        $this->load->helper('date');
         $time = time();
         $keyword = $this->user_keywords($this->ion_auth->user_id);
         foreach($keyword as $word) {
         $q = $this->db->select('user_id,pheed_id,datetime,pheed,COUNT(pheed_comments.comment_id) as comments')
         ->from('pheeds')
         ->join('pheed_comments','pheed_comments.P_id=pheeds.pheed_id','left')
         ->like('pheed',$word['keywords'])
         ->order_by('datetime','desc')
         ->get();
         $rows[] = $q->result_array();
         }
    
         return $rows;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using codeigniter to create a web app. I'm creating the drop down menus
i'm creating a web app that's running on an Advantage Database server, not my
I'm creating a web app using PHP and PostgreSQL. Database are too big and
I am creating a web app, similar to the like box code from Facebook:
So I am creating a web app, that will give each registered user a
I'm creating quick web app that needs to send a php-created message from within
I have been creating a web app and am looking to expand. In my
I'm creating a web-database driven offline web-app targeted at iOS devices. I'm trying to
I am creating a web app where if a user clicks on Link called
I'm creating a web app with Django. Since I'm very familiar with Apache I

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.