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;
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
add a comment |
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
Yourget_entryfunction 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
add a comment |
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
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
php codeigniter model-view-controller
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
Yourget_entryfunction 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
add a comment |
Yourget_entryfunction 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
add a comment |
2 Answers
2
active
oldest
votes
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.
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
|
show 7 more comments
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();
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
|
show 7 more comments
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.
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
|
show 7 more comments
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.
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.
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
|
show 7 more comments
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
|
show 7 more comments
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();
add a comment |
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();
add a comment |
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();
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();
answered Jun 2 '15 at 18:25
leesiderleesider
695 bronze badges
695 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Your
get_entryfunction 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