CodeIgniter Forums

Full Version: Make sure show result at top of list if replyto ==0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On my view thread I can get the posts for this thread how ever.

Question: How am I able to make sure the if the post has result['replyto'] == 0 Then will all ways be first on list

PHP Code:
public function getposts($thread_id$limit$offset)
{
    
$this->db->where('thread_id'$thread_id);
    
$this->db->limit($limit$offset);
    
$query $this->db->get('posts');
    return 
$query->result_array();




PHP Code:
<?php

class Viewthread extends CI_Controller
{
    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->library('parsedown');
        
$this->load->model('forum/thread_model');
        
$this->load->model('forum/post_model');
    }

    public function 
index()
    {
        
$this->load->library('pagination');

        
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        
$config['base_url'] = base_url('viewthread/' $this->uri->segment(2));
        
$config['total_rows'] = $this->post_model->totalpostsforthread($this->uri->segment(2));
        
$config['per_page'] = 20;

        
$this->pagination->initialize($config);

        
$data['posts'] = array();

        
$results $this->getposts($this->uri->segment(2), $config["per_page"], $page);

        foreach (
$results as $result)
        {
            if (
$result['replyto'] > 0) {

                
$data['posts'][] = array(
                    
'title' => 'RE: ' $result['title'],
                    
'message' => $this->parsedown->text($result['message'])
                );

            } else {

                
$data['posts'][] = array(
                    
'title' => $result['title'],
                    
'message' => $this->parsedown->text($result['message'])
                );                
            }
        }

        
$this->template->render('forum/viewthread'$templates = array(), $data);
    }

Use order_by on your replyto after your where cause
(06-24-2017, 02:30 AM)InsiteFX Wrote: [ -> ]Use order_by on your replyto after your where cause

Do you mean some thing like $this->db->orderby('replyto', 'asc');