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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:59:25+00:00 2026-06-14T12:59:25+00:00

I use codeigniter to generate JSON. This is my current structure: Model articles: <?php

  • 0

I use codeigniter to generate JSON. This is my current structure:

Model articles:

<?php
class Articles_model extends CI_Model {

 public function __construct()
     {
  $this->load->database();
 }

 public function get_articles()
{
  $this->db->order_by("HdOrder", "asc");
  $query = $this->db->get('articles');

  return $query->result_array();

}
} 

Controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Json extends CI_Controller {


 public function __construct()
 {
  parent::__construct();
  $this->load->model('articles_model');
 }

 public function index()
{
 $data['articles'] = $this->articles_model->get_articles();

 $this->load->view('json', $data);

}
}

And my view:

<?php header('Access-Control-Allow-Origin: *'); ?>

<?php
echo '{"articles":'.json_encode($articles).'}';
?> 

Now I need to pass two get parameters to this json so I can return it in pages. I have done it in php and it works. Below is the php code without CI:

<?php
$link = mysql_pconnect("localhost", "user", "pass") or die("Could not connect");
mysql_select_db("dbase") or die("Could not select database");

//GET page/count
$count=10;$offset=0;
if (isset($_GET['count'])) $count=$_GET['count']*1;
if (isset($_GET['page']))  $offset=$_GET['page']*$count*1;

$arr = array();

$rs = mysql_query("SELECT * FROM bannersright 
                   ORDER BY HdOrder 
                   LIMIT $offset,$count"); #<-HERE

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}

echo '{"bannersright":'.json_encode($arr).'}';

?>

Now how do I do this in my CodeIgniter structure? How should I pass my $offset and $count variables from my view-controller-model to set them as limit values for the mysql query? Actually I have found a tutorial on how to pass a varuable to the controller But I’m still not sure how to pass the same values to the model and then return the query to the same controller. And I’m not pretty sure if that is the correct approach to the problem.

I would like to solve it as simple as possible though.

  • 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-14T12:59:26+00:00Added an answer on June 14, 2026 at 12:59 pm

    You just need to pass parameters like this……….

    public function controller_name($param1, $param2) {
    
          $result = $this->model->get_result($param1, $param2);
    
          $data = array();
          $data['result'] = $result;
          $this->load->view('view_file_name', $data);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this PHP/CodeIgniter code to generate events on fullCalendar $('#calendar').fullCalendar({ events: [ <?php
I'm using the CodeIgniter calendar class to generate an availability calendar. I use a
I am trying to use the XMLWriter class in PHP to generate XML. I
I use Codeigniter platform to make a website I used this .load script to
I'm trying to use the PDO MySQL driver in my CodeIgniter application. This is
I have been using the encryption class of codeigniter (PHP framework) for a while
On Codeigniter , I'm using phpThumb to generate images. I didn't use the built-in
I use CodeIgniter 2.1 and my production server was updated to PHP 5.4.3-1, and
I'm going to use Codeigniter's session data for my login system, but first I
I'm trying to use CodeIgniter for multiple applications along with mod_rewrite for the application

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.