Welcome Guest, Not a member yet? Register   Sign In
Make sure show result at top of list if replyto ==0
#1

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);
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

Use order_by on your replyto after your where cause
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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');
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB