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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:48:27+00:00 2026-05-29T22:48:27+00:00

I have a function in my model for selecting items from a database and

  • 0

I have a function in my model for selecting items from a database and returning it as an array. My question is, how can I manually create the array, so that I can for example, change the date format?

Here is what I have:

$sql = 'SELECT * FROM prayer_requests ORDER BY id DESC';
        $query = $this->db->query($sql);

        if($query->num_rows() > 0) return $query->result();
        else return FALSE;

I’m guessing I would need some kind of loop? I know it must be simple, but can’t figure out exactly how to do it.

  • 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-29T22:48:28+00:00Added an answer on May 29, 2026 at 10:48 pm

    If you want to get the result as an array, you can use result_array() instead of result().
    You can read more about generating results with CodeIgniter here: http://codeigniter.com/user_guide/database/results.html

    Ex:

    $query = $this->db->query("YOUR QUERY");
    $rows = $query->result_array(); // $rows is now an array containing all the rows from the query result
    

    EDIT:
    If you want to modify the data before putting it into the array. You’ll need a loop, and while in the loop, use any functions necessary to change the data you want. Then assign it back the loop variable, and append it to an array (which has already been initialized before the loop).

    $rows = array();
    foreach($query->result_array() as $row)
    {
        $row['some_key'] = change_data($row['some_key');
        $rows[] = $row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a function in my Navigation model that executes a query, and
I have two methods in my model. One is selecting and returning the data
I have a function in my Comic Model as such: <?php class Comic extends
i have the following function to override the default save function in a model
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
I have function getCartItems in cart.js and I want to call that function in
I have a ui that looks like this: +--------+---------------+ | model1 | model details
I have code that adds list items to an unordered list, and associated with
I have a table that displays from db all infrastructures (their name, description, performance).
Hello all I have class that inherited from Qtreeview and I implement simple (

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.