Welcome Guest, Not a member yet? Register   Sign In
Passing array of DB results to view
#1

[eluser]Unknown[/eluser]
Hi

I am new to codeigniter, but pretty excited by what I have seen. I am having a problem passing an array of db results to the view.

I know people are going to tell me to put my DB code in my model but that really isn't the issue here.

Here is my controller

Code:
<?php

class Admin extends CI_Controller
{

function __construct()
{
  parent::__construct();
  $this->load->library('ion_auth');
  $this->load->library('session');
  $this->load->library('form_validation');
  $this->load->database();
  $this->load->helper('url');
  $this->load->helper('form');
  
  if(!$this->ion_auth->is_admin())
  {
   $this->set_flashdata['message'] = 'You do not have access to this area';
   redirect('auth/login');
  
  }
  
}
  
function index()
{

  $this->load->view('admin');

}

function deals()
{

  //get the current deals from the database
  $query = $this->db->get('deals');
  $data['current_deals'] = $query->result_array();

  $this->load->view('current_deals',$data);

}

}

and the view

Code:
<?php $this->load->view('header'); ?>
  
<div class="mainInfo">  
   <h2>Current Deals</h2>
  
   <table class="current_deals">
    <tr>
     <td class="title_head">
      <b>Deal Title</b>
     </td>
     <td class="actions_head">
      <b>Actions</b>
     </td>
    </tr>
    
    &lt;?php
    
    echo '<pre>';
    print_r($current_deals);
    echo '</pre>';

    foreach($current_deals as $row);
    {
     echo '<tr>';
     echo '<td class="title_body">'.$row['deal_title'].'</td>';
     echo '<td class="actions_body">&lt;LINK CODE'.$row['deal_id'].'"&gt;Edit Deal</a> | &lt;LINK CODE '.$row['deal_id'].'"&gt;Remove Deal</a></td>';
     echo '</tr>';
    
    }
    ?&gt;
    
   </table>
</div>


&lt;?php $this->load->view('footer'); ?&gt;

No matter what format I pass it in I only ever get one result. If I print_r the array the results are there, but when I loop through I only get the 1 result. A little confused :-(

Look forward to your help.




Theme © iAndrew 2016 - Forum software by © MyBB