I am working on a forum script. it works when i do it mostly in the view but i really want to do is make it smarty friendly.
i can not for the life of me figure out how to get it to pass the data right.
this is for my category section
Code:
$rows = $this->db->query("SELECT * FROM forum_category");
$reputation = array();
foreach ($rows->result_array() as $row)
{
$rep = array();
$rep['name'] = $row['name'];
$rep['id'] = $row['id'];
// Add this array to the other one
$reputation[] = $rep;
}
return $reputation;
this is for the topics of the forums
Code:
$sql = $this->db->query("SELECT * FROM forum_topic WHERE cat_id='$slug'");
$war = array();
foreach ($sql->result_array() as $rows)
{
$reps = array();
$reps['subject'] = $rows['subject'];
$reps['id'] = $rows['id'];
$reps['desc'] = $rows['description'];
$wars[] = $reps;
}
return $wars;
how would i go about getting this to work with smarty and codeigniter.
this is my controller for the forum.
Code:
$data['result'] = $this->forum_model->getthreads();
$war = array();
foreach ($data['result'] as $rows) {
$war[] = $this->forum_model->showtopic($rows['id']);
}
$data['topic'] = $war;
this is what my original code looks like on the view
Code:
public function showthreads()
{
$query=$this->db->query("SELECT * FROM forum_category");
foreach($query->result_array() as $row):
?>
<table class='table forum table-striped'>
<thead>
<tr>
<th class='cell-stat'></th>
<th>
<h3><?=$row['name'];?></h3>
</th>
<th class='cell-stat text-center hidden-xs hidden-sm'>Topics</th>
<th class='cell-stat text-center hidden-xs hidden-sm'>Posts</th>
<th class='cell-stat-2x hidden-xs hidden-sm'>Last Post</th>
</tr>
</thead>
<tbody>
<?
$query=$this->db->query("SELECT * FROM forum_topic WHERE cat_id=$row[id]");
foreach($query->result() as $topic):
$total=$this->db->query("SELECT * FROM forum_thread WHERE thr_id='$topic->id'");
$thread=$total->row();
$totals=$this->db->query("SELECT * FROM forum_posts WHERE thr_id='$topic->id'");
$post=$totals->row();
if($total->num_rows() == 0)
{
$threads="<td class='hidden-xs hidden-sm'>by <a href='#'>jane doe</a><br><small><i class='fa fa-clock-o'></i> 3 months ago</small></td>";
}else
{
$threads="<td class='hidden-xs hidden-sm'>by <a href='".base_url()."profile/$thread->poster'>$thread->poster</a><br><small><i class='fa fa-clock-o'></i> ".date("M d, Y g:i",$thread->date)."</small></td>";
}
?>
<tr>
<td class='text-center'><i class='fa fa-question fa-2x text-primary'></i></td>
<td>
<h4><a href='<?=base_url();?>forum/<?=$topic->id;?>'><?=$topic->subject;?></a><br><small><?=$topic->description;?></small></h4>
</td>
<td class='text-center hidden-xs hidden-sm'><a href='#'><?=$total->num_rows();?></a></td>
<td class='text-center hidden-xs hidden-sm'><a href='#'><?=$totals->num_rows();?></a></td>
<?=$threads;?>
</tr>
<? endforeach;?>
</tbody>
</table>
<?
endforeach;
}