Codeigniter php MVCWhat are MVP and MVC and what is the difference?How can I prevent SQL injection in PHP?Deleting an element from an array in PHPFatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)What is the difference between MVC and MVVM?How do you parse and process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Reference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?

Why did MS-DOS applications built using Turbo Pascal fail to start with a division by zero error on faster systems?

How big would a Daddy Longlegs Spider need to be to kill an average Human?

Are illustrations in novels frowned upon?

What is the hex versus octal timeline?

In what ways can a Non-paladin access Paladin spells?

Can a character spend multiple hit dice at level 1?

Is "stainless" a bulk or a surface property of stainless steel?

Why were movies shot on film shot at 24 frames per second?

Can you feel passing through the sound barrier in an F-16?

Vacuum collapse -- why do strong metals implode but glass doesn't?

Is it best to use a tie when using 8th notes off the beat?

How is "sein" conjugated in this sub-sentence?

Was Switzerland really impossible to invade during WW2?

How do I find the fastest route from Heathrow to an address in London using all forms of transport?

What professions would a medieval village with a population of 100 need?

What is the evidence on the danger of feeding whole blueberries and grapes to infants and toddlers?

Don't understand MOSFET as amplifier

Have only girls been born for a long time in this village?

Potential new partner angry about first collaboration - how to answer email to close up this encounter in a graceful manner

Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?

Why doesn't mathematics collapse even though humans quite often make mistakes in their proofs?

How to persuade recruiters to send me the Job Description?

Why doesn't the Falcon-9 first stage use three legs to land?

Solve a logarithmic equation by NSolve



Codeigniter php MVC


What are MVP and MVC and what is the difference?How can I prevent SQL injection in PHP?Deleting an element from an array in PHPFatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)What is the difference between MVC and MVVM?How do you parse and process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Reference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have a table called 'News' with three columns: 'id', 'title' and 'details'



I have a function ('get_entry') inside a codeigniter model class (called 'News_model')



function get_entry()

$this->load->database();
return $this->db->select('id,title,details')->from ('news');
$data['newsarray'] = $this->db->row_array();
return $data['newsarray'];



I am connecting to the db so that is not the problem.I want to return an iterable array from get_entry() by calling the function from a controller file with the followlwing code. I want to push it into another array (called '$data['theNews']') using the code below.



foreach ($this->News_model->get_entry() as $key => $value)
array_push($data['theNews'],$value->title);



I have been using the code on this (https://www.codeigniter.com/user_guide/general/models.html) as a template (in particular the function 'get_last_ten_entries()' but I think I am close with the code I posted above. I would appreciate any help.










share|improve this question


























  • Your get_entry function retunr 1 row only. If you want to iterate over several rows - rewrite your function so it returns 10 or more results.

    – u_mulder
    May 30 '15 at 14:14











  • Please post what you are getting in $data['newsarray']

    – Avinash
    May 30 '15 at 14:18






  • 1





    The built-in code snippets are only for JavaScript/HTML/CSS... you cannot run PHP in your OP. Removed. Thanks.

    – Sparky
    May 30 '15 at 14:18











  • Here you can find most recent documentation for framework: v3, v2.

    – Tpojka
    May 30 '15 at 15:43

















0















I have a table called 'News' with three columns: 'id', 'title' and 'details'



I have a function ('get_entry') inside a codeigniter model class (called 'News_model')



function get_entry()

$this->load->database();
return $this->db->select('id,title,details')->from ('news');
$data['newsarray'] = $this->db->row_array();
return $data['newsarray'];



I am connecting to the db so that is not the problem.I want to return an iterable array from get_entry() by calling the function from a controller file with the followlwing code. I want to push it into another array (called '$data['theNews']') using the code below.



foreach ($this->News_model->get_entry() as $key => $value)
array_push($data['theNews'],$value->title);



I have been using the code on this (https://www.codeigniter.com/user_guide/general/models.html) as a template (in particular the function 'get_last_ten_entries()' but I think I am close with the code I posted above. I would appreciate any help.










share|improve this question


























  • Your get_entry function retunr 1 row only. If you want to iterate over several rows - rewrite your function so it returns 10 or more results.

    – u_mulder
    May 30 '15 at 14:14











  • Please post what you are getting in $data['newsarray']

    – Avinash
    May 30 '15 at 14:18






  • 1





    The built-in code snippets are only for JavaScript/HTML/CSS... you cannot run PHP in your OP. Removed. Thanks.

    – Sparky
    May 30 '15 at 14:18











  • Here you can find most recent documentation for framework: v3, v2.

    – Tpojka
    May 30 '15 at 15:43













0












0








0








I have a table called 'News' with three columns: 'id', 'title' and 'details'



I have a function ('get_entry') inside a codeigniter model class (called 'News_model')



function get_entry()

$this->load->database();
return $this->db->select('id,title,details')->from ('news');
$data['newsarray'] = $this->db->row_array();
return $data['newsarray'];



I am connecting to the db so that is not the problem.I want to return an iterable array from get_entry() by calling the function from a controller file with the followlwing code. I want to push it into another array (called '$data['theNews']') using the code below.



foreach ($this->News_model->get_entry() as $key => $value)
array_push($data['theNews'],$value->title);



I have been using the code on this (https://www.codeigniter.com/user_guide/general/models.html) as a template (in particular the function 'get_last_ten_entries()' but I think I am close with the code I posted above. I would appreciate any help.










share|improve this question
















I have a table called 'News' with three columns: 'id', 'title' and 'details'



I have a function ('get_entry') inside a codeigniter model class (called 'News_model')



function get_entry()

$this->load->database();
return $this->db->select('id,title,details')->from ('news');
$data['newsarray'] = $this->db->row_array();
return $data['newsarray'];



I am connecting to the db so that is not the problem.I want to return an iterable array from get_entry() by calling the function from a controller file with the followlwing code. I want to push it into another array (called '$data['theNews']') using the code below.



foreach ($this->News_model->get_entry() as $key => $value)
array_push($data['theNews'],$value->title);



I have been using the code on this (https://www.codeigniter.com/user_guide/general/models.html) as a template (in particular the function 'get_last_ten_entries()' but I think I am close with the code I posted above. I would appreciate any help.







php codeigniter model-view-controller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 15:47









Manu K M

6365 silver badges18 bronze badges




6365 silver badges18 bronze badges










asked May 30 '15 at 14:04









leesiderleesider

695 bronze badges




695 bronze badges















  • Your get_entry function retunr 1 row only. If you want to iterate over several rows - rewrite your function so it returns 10 or more results.

    – u_mulder
    May 30 '15 at 14:14











  • Please post what you are getting in $data['newsarray']

    – Avinash
    May 30 '15 at 14:18






  • 1





    The built-in code snippets are only for JavaScript/HTML/CSS... you cannot run PHP in your OP. Removed. Thanks.

    – Sparky
    May 30 '15 at 14:18











  • Here you can find most recent documentation for framework: v3, v2.

    – Tpojka
    May 30 '15 at 15:43

















  • Your get_entry function retunr 1 row only. If you want to iterate over several rows - rewrite your function so it returns 10 or more results.

    – u_mulder
    May 30 '15 at 14:14











  • Please post what you are getting in $data['newsarray']

    – Avinash
    May 30 '15 at 14:18






  • 1





    The built-in code snippets are only for JavaScript/HTML/CSS... you cannot run PHP in your OP. Removed. Thanks.

    – Sparky
    May 30 '15 at 14:18











  • Here you can find most recent documentation for framework: v3, v2.

    – Tpojka
    May 30 '15 at 15:43
















Your get_entry function retunr 1 row only. If you want to iterate over several rows - rewrite your function so it returns 10 or more results.

– u_mulder
May 30 '15 at 14:14





Your get_entry function retunr 1 row only. If you want to iterate over several rows - rewrite your function so it returns 10 or more results.

– u_mulder
May 30 '15 at 14:14













Please post what you are getting in $data['newsarray']

– Avinash
May 30 '15 at 14:18





Please post what you are getting in $data['newsarray']

– Avinash
May 30 '15 at 14:18




1




1





The built-in code snippets are only for JavaScript/HTML/CSS... you cannot run PHP in your OP. Removed. Thanks.

– Sparky
May 30 '15 at 14:18





The built-in code snippets are only for JavaScript/HTML/CSS... you cannot run PHP in your OP. Removed. Thanks.

– Sparky
May 30 '15 at 14:18













Here you can find most recent documentation for framework: v3, v2.

– Tpojka
May 30 '15 at 15:43





Here you can find most recent documentation for framework: v3, v2.

– Tpojka
May 30 '15 at 15:43












2 Answers
2






active

oldest

votes


















1













About your code:



You have two 'return' in your get_entry function:



function get_entry()

$this->load->database();
// First
return $this->db->select('id,title,details')->from ('news');
$data['newsarray'] = $this->db->row_array();
// Second
return $data['newsarray'];



Change it to:



function get_entry()

$this->load->database();
$query = $this->db->select('id,title,details')->from('news');
$data['newsarray'] = $query->row_array();
return $data['newsarray'];



It should work now.



Some advices:



Don't use Codeigniter 2 anymore. Version 3 is alive.



If you plan to return whole table columns, i suggest you to use the following code for the query:



$query = $this->db->get('news', 1, 20);


Where 1, 20 is the limit.



Now you can get the result:



return $query->result();


A simple example:



function get_entry()

$this->load->database();
$query = $this->db->get('news', 1, 20);
return $query->result();



This method returns the query result as an array of objects that you can print like so in your controller:



$news_array = $this->News_model->get_entry();
foreach ($news_array as $news)

echo $news->id;



Look at CI 3 Query Builder query builder for more examples.



One more suggestion, just autoload the database library in application/config/autoload.php if you need it globally.






share|improve this answer



























  • Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

    – Sparky
    May 30 '15 at 14:20












  • Yes, i forgot to remove asterisks, thanks. :)

    – Kvash
    May 30 '15 at 14:28












  • Can you please post the error? Which code are you using? The first or the last example?

    – Kvash
    May 30 '15 at 14:54












  • Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

    – leesider
    May 30 '15 at 14:58











  • Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

    – Kvash
    May 30 '15 at 15:00



















1













Changing the code to this in the function worked:



function get_entry()

$this->load->database();
$query = $this->db->get('news');
//return $query->result();

foreach ($query->result() as $row)

echo "</br>";
echo $row->id;
echo "</br>";
echo $row->title;
echo "</br>";
echo $row->details;
echo "</br>";





Calling the function like so prints it out:



$news_array = $this->News_model->get_entry();






share|improve this answer



























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30547123%2fcodeigniter-php-mvc%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1













    About your code:



    You have two 'return' in your get_entry function:



    function get_entry()

    $this->load->database();
    // First
    return $this->db->select('id,title,details')->from ('news');
    $data['newsarray'] = $this->db->row_array();
    // Second
    return $data['newsarray'];



    Change it to:



    function get_entry()

    $this->load->database();
    $query = $this->db->select('id,title,details')->from('news');
    $data['newsarray'] = $query->row_array();
    return $data['newsarray'];



    It should work now.



    Some advices:



    Don't use Codeigniter 2 anymore. Version 3 is alive.



    If you plan to return whole table columns, i suggest you to use the following code for the query:



    $query = $this->db->get('news', 1, 20);


    Where 1, 20 is the limit.



    Now you can get the result:



    return $query->result();


    A simple example:



    function get_entry()

    $this->load->database();
    $query = $this->db->get('news', 1, 20);
    return $query->result();



    This method returns the query result as an array of objects that you can print like so in your controller:



    $news_array = $this->News_model->get_entry();
    foreach ($news_array as $news)

    echo $news->id;



    Look at CI 3 Query Builder query builder for more examples.



    One more suggestion, just autoload the database library in application/config/autoload.php if you need it globally.






    share|improve this answer



























    • Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

      – Sparky
      May 30 '15 at 14:20












    • Yes, i forgot to remove asterisks, thanks. :)

      – Kvash
      May 30 '15 at 14:28












    • Can you please post the error? Which code are you using? The first or the last example?

      – Kvash
      May 30 '15 at 14:54












    • Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

      – leesider
      May 30 '15 at 14:58











    • Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

      – Kvash
      May 30 '15 at 15:00
















    1













    About your code:



    You have two 'return' in your get_entry function:



    function get_entry()

    $this->load->database();
    // First
    return $this->db->select('id,title,details')->from ('news');
    $data['newsarray'] = $this->db->row_array();
    // Second
    return $data['newsarray'];



    Change it to:



    function get_entry()

    $this->load->database();
    $query = $this->db->select('id,title,details')->from('news');
    $data['newsarray'] = $query->row_array();
    return $data['newsarray'];



    It should work now.



    Some advices:



    Don't use Codeigniter 2 anymore. Version 3 is alive.



    If you plan to return whole table columns, i suggest you to use the following code for the query:



    $query = $this->db->get('news', 1, 20);


    Where 1, 20 is the limit.



    Now you can get the result:



    return $query->result();


    A simple example:



    function get_entry()

    $this->load->database();
    $query = $this->db->get('news', 1, 20);
    return $query->result();



    This method returns the query result as an array of objects that you can print like so in your controller:



    $news_array = $this->News_model->get_entry();
    foreach ($news_array as $news)

    echo $news->id;



    Look at CI 3 Query Builder query builder for more examples.



    One more suggestion, just autoload the database library in application/config/autoload.php if you need it globally.






    share|improve this answer



























    • Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

      – Sparky
      May 30 '15 at 14:20












    • Yes, i forgot to remove asterisks, thanks. :)

      – Kvash
      May 30 '15 at 14:28












    • Can you please post the error? Which code are you using? The first or the last example?

      – Kvash
      May 30 '15 at 14:54












    • Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

      – leesider
      May 30 '15 at 14:58











    • Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

      – Kvash
      May 30 '15 at 15:00














    1












    1








    1







    About your code:



    You have two 'return' in your get_entry function:



    function get_entry()

    $this->load->database();
    // First
    return $this->db->select('id,title,details')->from ('news');
    $data['newsarray'] = $this->db->row_array();
    // Second
    return $data['newsarray'];



    Change it to:



    function get_entry()

    $this->load->database();
    $query = $this->db->select('id,title,details')->from('news');
    $data['newsarray'] = $query->row_array();
    return $data['newsarray'];



    It should work now.



    Some advices:



    Don't use Codeigniter 2 anymore. Version 3 is alive.



    If you plan to return whole table columns, i suggest you to use the following code for the query:



    $query = $this->db->get('news', 1, 20);


    Where 1, 20 is the limit.



    Now you can get the result:



    return $query->result();


    A simple example:



    function get_entry()

    $this->load->database();
    $query = $this->db->get('news', 1, 20);
    return $query->result();



    This method returns the query result as an array of objects that you can print like so in your controller:



    $news_array = $this->News_model->get_entry();
    foreach ($news_array as $news)

    echo $news->id;



    Look at CI 3 Query Builder query builder for more examples.



    One more suggestion, just autoload the database library in application/config/autoload.php if you need it globally.






    share|improve this answer















    About your code:



    You have two 'return' in your get_entry function:



    function get_entry()

    $this->load->database();
    // First
    return $this->db->select('id,title,details')->from ('news');
    $data['newsarray'] = $this->db->row_array();
    // Second
    return $data['newsarray'];



    Change it to:



    function get_entry()

    $this->load->database();
    $query = $this->db->select('id,title,details')->from('news');
    $data['newsarray'] = $query->row_array();
    return $data['newsarray'];



    It should work now.



    Some advices:



    Don't use Codeigniter 2 anymore. Version 3 is alive.



    If you plan to return whole table columns, i suggest you to use the following code for the query:



    $query = $this->db->get('news', 1, 20);


    Where 1, 20 is the limit.



    Now you can get the result:



    return $query->result();


    A simple example:



    function get_entry()

    $this->load->database();
    $query = $this->db->get('news', 1, 20);
    return $query->result();



    This method returns the query result as an array of objects that you can print like so in your controller:



    $news_array = $this->News_model->get_entry();
    foreach ($news_array as $news)

    echo $news->id;



    Look at CI 3 Query Builder query builder for more examples.



    One more suggestion, just autoload the database library in application/config/autoload.php if you need it globally.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 30 '15 at 15:20

























    answered May 30 '15 at 14:19









    KvashKvash

    681 silver badge8 bronze badges




    681 silver badge8 bronze badges















    • Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

      – Sparky
      May 30 '15 at 14:20












    • Yes, i forgot to remove asterisks, thanks. :)

      – Kvash
      May 30 '15 at 14:28












    • Can you please post the error? Which code are you using? The first or the last example?

      – Kvash
      May 30 '15 at 14:54












    • Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

      – leesider
      May 30 '15 at 14:58











    • Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

      – Kvash
      May 30 '15 at 15:00


















    • Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

      – Sparky
      May 30 '15 at 14:20












    • Yes, i forgot to remove asterisks, thanks. :)

      – Kvash
      May 30 '15 at 14:28












    • Can you please post the error? Which code are you using? The first or the last example?

      – Kvash
      May 30 '15 at 14:54












    • Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

      – leesider
      May 30 '15 at 14:58











    • Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

      – Kvash
      May 30 '15 at 15:00

















    Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

    – Sparky
    May 30 '15 at 14:20






    Asterisks are not part of the code. Simply use comments to indicate the line. // <-- this line

    – Sparky
    May 30 '15 at 14:20














    Yes, i forgot to remove asterisks, thanks. :)

    – Kvash
    May 30 '15 at 14:28






    Yes, i forgot to remove asterisks, thanks. :)

    – Kvash
    May 30 '15 at 14:28














    Can you please post the error? Which code are you using? The first or the last example?

    – Kvash
    May 30 '15 at 14:54






    Can you please post the error? Which code are you using? The first or the last example?

    – Kvash
    May 30 '15 at 14:54














    Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

    – leesider
    May 30 '15 at 14:58





    Since I changed the 'get_entry' function to what you posted I am not getting any errors when I run the php page but now when I try to call this function from the controller like below I get nothing back. I want to add each row returned from the function to an array called 'theNews' but for a start I just want to echo out what is coming back so I have the line that adds to the array commented out as you can see. $data['theNews']=array(); foreach ($this->News_model->get_entry() as $key => $value) echo $key;//array_push($data['theNews'],$value->title);

    – leesider
    May 30 '15 at 14:58













    Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

    – Kvash
    May 30 '15 at 15:00






    Ok, got it, but i can't understand which of the function you're using, is this one? : function get_entry() $this->load->database(); $query = $this->db->get('news', 1, 20); return $query->result();

    – Kvash
    May 30 '15 at 15:00














    1













    Changing the code to this in the function worked:



    function get_entry()

    $this->load->database();
    $query = $this->db->get('news');
    //return $query->result();

    foreach ($query->result() as $row)

    echo "</br>";
    echo $row->id;
    echo "</br>";
    echo $row->title;
    echo "</br>";
    echo $row->details;
    echo "</br>";





    Calling the function like so prints it out:



    $news_array = $this->News_model->get_entry();






    share|improve this answer





























      1













      Changing the code to this in the function worked:



      function get_entry()

      $this->load->database();
      $query = $this->db->get('news');
      //return $query->result();

      foreach ($query->result() as $row)

      echo "</br>";
      echo $row->id;
      echo "</br>";
      echo $row->title;
      echo "</br>";
      echo $row->details;
      echo "</br>";





      Calling the function like so prints it out:



      $news_array = $this->News_model->get_entry();






      share|improve this answer



























        1












        1








        1







        Changing the code to this in the function worked:



        function get_entry()

        $this->load->database();
        $query = $this->db->get('news');
        //return $query->result();

        foreach ($query->result() as $row)

        echo "</br>";
        echo $row->id;
        echo "</br>";
        echo $row->title;
        echo "</br>";
        echo $row->details;
        echo "</br>";





        Calling the function like so prints it out:



        $news_array = $this->News_model->get_entry();






        share|improve this answer













        Changing the code to this in the function worked:



        function get_entry()

        $this->load->database();
        $query = $this->db->get('news');
        //return $query->result();

        foreach ($query->result() as $row)

        echo "</br>";
        echo $row->id;
        echo "</br>";
        echo $row->title;
        echo "</br>";
        echo $row->details;
        echo "</br>";





        Calling the function like so prints it out:



        $news_array = $this->News_model->get_entry();







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 2 '15 at 18:25









        leesiderleesider

        695 bronze badges




        695 bronze badges






























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30547123%2fcodeigniter-php-mvc%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해