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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:00:11+00:00 2026-05-15T21:00:11+00:00

I have a CI Model set up with this function and ActiveRecord: function get_open_competitions()

  • 0

I have a CI Model set up with this function and ActiveRecord:

function get_open_competitions()
{                                       
    $this->db->select('*, TO_DAYS(closingdate) - TO_DAYS(CURDATE()) AS days')
                ->from('challenges')
                ->where('closingdate >','CURDATE()')
                ->order_by('days','asc');

    $query = $this->db->get();          
    return $query;
}

I’m 99.9% confident that would run this query:

SELECT *, TO_DAYS(closingdate) - TO_DAYS(CURDATE()) AS days
FROM challenges
WHERE closingdate > CURDATE()
ORDER BY days ASC

When I put that plain query through phpMyAdmin or Sequel Pro, it returns 5 rows – as expected – from the database. However when I call in the challenges controller the following code:

    function index()
{
    // Fetch the Open for Entry competitions
    $data['open'] = $this->cm->get_open_competitions(); 
    // Fetch the Open for Voting competitions
    $data['voting'] = $this->cm->get_voting_competitions();
    // Fetch the Ended Competitions
    $data['ended'] = $this->cm->get_ended_competitions();   

    $data['colwide'] = 'challenges/challengeshome';
    $this->load->view('templatewide',$data);
}

… And then in the view file call it up like this…

<h2>Open for Entry</h2>

<hr/>

<?php foreach ($open->result() as $row) { ?>
    <h3>
        <?php echo anchor('challenges/view/'.$row->id, $row->title);?> - 
        <i>Challenge ends and voting begins in <?php echo $row->days;?> days</i>
    </h3>
    <h4> <?php echo $row->description;?> </h4>
<?php } ?>

… nothing is output!

This is confusing me, because I’m very certain I’ve got a valid query, and also I have two other Model functions – get_ended_competitions and get_voting_competitions – both of which I’m using alongside this which work fine. The code is definitely no different.

What am I doing wrong?! :S

Thanks!

Jack

Edit: Nothing is written to either the CodeIgniter log, or to PHP’s error log.

  • 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-15T21:00:12+00:00Added an answer on May 15, 2026 at 9:00 pm

    Before anything else, enable the profiler in your controller constructor:

    $this->output->enable_profiler(true);
    

    this way you’ll see exactly what queries are generated.

    LE: also, don’t forget about $this->db->last_query(); 😉

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

Sidebar

Related Questions

I have fit a simple bi-variate VAR model to this data set and I
This is my custom model binder. I have my breakpoint set at BindModel but
I have a two models set up like this: class User < ActiveRecord::Base #
I'm trying to use PHP ActiveRecord in Codeigniter. I have a model like this:
In my model named Profile_model I have this function which retrieves profile data for
I have a simple function within my model to set a completed datetime column
I have a model set out like so: class Rating # user_id, author_id end
Lets say I have model inheritance set up in the way defined below. class
I have a model form that contains a DecimalField() with max_digits set to 5.
I have a model named Aggelia (it's greek for classified ad) and have set

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.