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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:42:30+00:00 2026-05-24T19:42:30+00:00

Am trying to encode an array to json for use with jquery. This is

  • 0

Am trying to encode an array to json for use with jquery.
This is the function from my model

function get_latest_pheeds() {
        $this->load->helper('date');
         $time = time();
         $q = $this->db->select("user_id,pheed_id,pheed,datetime,COUNT(pheed_comments.comment_id) as comments")
                        ->from('pheeds')
                        ->join('pheed_comments','pheed_comments.P_id=pheeds.pheed_id','left')
                        ->group_by('pheed_id')
                        ->order_by('datetime','desc')
                        ->limit(30);
        $rows = $q->get();
            foreach($rows->result_array() as $row) {
                $data['user_id'] = $row['user_id'];
                $data['pheed_id'] = $row['pheed_id'];
                $data['pheed'] = $row['pheed'];
                $data['comments'] = $row['comments'];
                $data['datetime'] = timespan($row['datetime'],$time);
            }
            return $data;
     }

And this is from my controller

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;
        }
    }

It returns only 1 row from the database when I run the code in the browser.
Please help me out

  • 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-24T19:42:31+00:00Added an answer on May 24, 2026 at 7:42 pm

    You are overwriting data in every iteration !!

    Use something like

        $data[] = array(
        'user_id' => $row['user_id'];
        'pheed_id' => $row['pheed_id']; 
        'pheed' => $row['pheed'];
        'comments' => $row['comments'];
        'datetime' => timespan($row['datetime'],$time); 
        ) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to use json_decode to combine a few json objects and then re-encode
Okay I have been racking my brain trying to build a JSON array from
I am trying to encode an array which contains floats and NaN into JSON
I'm trying to use the new autocomplete function in jQuery UI, but I'm having
I'm trying to convert a JSON object/array from the Google Directions API v3 to
I am trying to use jQuery's fancy autocomplete function but I have a problem
I trying to build a JavaScript function which will grab a JSON encoded array
I am trying to json encode an array,it does encode but i get lots
I'm trying to load some data via. jquery $get_desc = SELECT tekst_id,overskrift FROM rr_tekster
I'm trying to encode a Python array into json using simplejson.dumps: In [30]: s1

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.