Welcome Guest, Not a member yet? Register   Sign In
Help with array refencing database table.
#1

[eluser]spmckee[/eluser]
Greetings,

This is my first dive into CI and am loving it but running into a small snag. I can get the whole "Works Table" array and pass it on to the view for display but I need to change the values of "task_1, task_2 and task_3" into the names from the "Task Table", which is currently not happening.

Any help is greatly appreciated.

Thanks!

Works Table:
+++++++++++++++++++++++++++++++++++++++++++++++
ID name task_1 task_2 task_3
----------------------------------------------
1 Nike 1 3 3
2 Dell 3 1 5
3 IBM 4 2
+++++++++++++++++++++++++++++++++++++++++++++++


Task Table:
++++++++++++++
ID name
--------------
1 Design
2 Development
3 Research
4 Concepting
++++++++++++++


The Model

Code:
class MOurWork extends My_Model{

    function MOurWork(){
        parent::My_Model();
    }
    
function getAllWorks(){
     $data = array();
     $query = $this->db->query('SELECT * FROM works WHERE active="1"');
     if ($query->num_rows() > 0){
       foreach ($query->result_array() as $row){
         $data[] = $row;    
       }
    }
    $query->free_result();
    return $data;
}
}

The Controller

Code:
<?php
class Our_work extends My_Controller {

  function our_work()
  {
    parent::My_Controller();
  }

  function index()
  {
      $data['main'] = 'our_work';
      $data['works'] = $this->MOurWork->getAllWorks();
      $this->load->view('template', $data);
  }
}
?>

The View

Code:
<div class="works-thumbs-container">
&lt;?php

if (count($works)){
    foreach ($works as $key => $list){
?&gt;

    <div class="works-thumb">
        <a href="#" title="&lt;?php echo $list['desc_short']; ?&gt;">
        <img class="img-web-thumb" alt="&lt;?php echo $list['project_name']; ?&gt; Thumbnail" src="images/works/&lt;?php echo $list[" />
        </a>
            
        <div class="tooltip">
               <p>This is a small Tooltip with the Classname 'Tooltip'</p>
        </div>
            
           <p>
        <ul>
        &lt;?php
                            
        for ($i = 1; $i < 3; $i++)
        {
        $task_key_name = 'task_name_'.$i;
        if ($list[$task_key_name]!='NULL'){ echo '<li>'.$list[$task_key_name].'</li>'; }
}
?&gt;
        </ul>
        </p>
    
        <p>&lt;?= $list['project_name']; ?&gt;</p>
    </div>

&lt;?php
   }
}
?&gt;
</div>


Messages In This Thread
Help with array refencing database table. - by El Forum - 01-09-2009, 12:44 PM
Help with array refencing database table. - by El Forum - 01-09-2009, 03:25 PM
Help with array refencing database table. - by El Forum - 01-09-2009, 05:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB