Welcome Guest, Not a member yet? Register   Sign In
Possibly bug or incorrect code?
#6

If it returns one row only then it must be because that the query only got one row, check the rows of your table and see if they are active, chances are there is only one row which has an active column set to true in your table.
PHP Code:
//path: proj/application/controllers/News.php
class News extends CI_Controller
{
 public function 
__construct ()
 {
 
 parent::__construct();
 
 $this->load->model("news_model");
 }
 public function 
index ()
 {
 
 $active_news $this->news_model->get_active_news();
 
 $data["active_news"] = $active_news;
 
 $this->load->view("news/index");
 }


PHP Code:
// oath: proj/application/models/News_model.php
class News_model extends CI_Model
{
 public function 
__construct ()
 {
 
 parent::__construct();
 
 $this->load->database();
 }
 public function 
get_active_news ()
 {
 
 $args = array(
 
  "active" => // assuming the column datatype is tinyint
 
 );
 
 $result $this->db->get_where("news"$args);
 
 $active_news $result->result_array();
 
 $result->free_result();
 
 return $active_news;
 }

PHP Code:
//path: proj/application/views/news/index.php
<!doctype html>
<
html>
 <
head> ... </head>
 <
body>
 
 <main>
 
  ...
 
   <article>
 
    <?php foreach ($active_news as $news) : ?>
       <h1><?php echo $news["title"?></h1>
       ...
     <?php endforeach; ?>
    </article>
  </main>
 </body>
</html> 
Reply


Messages In This Thread
Possibly bug or incorrect code? - by cyborg - 07-04-2017, 02:36 PM
RE: Possibly bug or incorrect code? - by Wouter60 - 07-04-2017, 10:42 PM
RE: Possibly bug or incorrect code? - by rtenny - 07-05-2017, 01:15 AM
RE: Possibly bug or incorrect code? - by cyborg - 07-05-2017, 05:44 AM
RE: Possibly bug or incorrect code? - by meSmashsta - 07-05-2017, 05:53 PM
RE: Possibly bug or incorrect code? - by Wouter60 - 07-05-2017, 10:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB