Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get selected numbers of character from column using Codeigniter?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 537
    Comment on it

    Hello Readers, If you are using CodeIgniter you want to fetch limited MySQL results then in this blog we will learn how to to this.

     

    Suppose you want only first 200 chars of a field then you should only fetch limited results, this will reduce the unnecessary request and speed up your page speed. So let's get started building this.

     

    Step 1:- First create a model and write its MySql syntax for fetching the limited results. It will go like this:-

    public function viewBlogs($page_num,$per_page)
    	{ 
    		$this->db->select('blogs.id, title, LEFT(content , 200) as content, blogs.modified, user_id, users.first_name, users.last_name, photo');
    		$this->db->from('blogs');
    		$this->db->join('users','users.id = blogs.user_id');
    		$this->db->join('blog_photos','blog_photos.blog_id = blogs.id');
    		$this->db->where('blogs.deleted', '0');
    		$this->db->where('blogs.status', '1');
    		$this->db->order_by("id", "desc");
    		$this->db->limit($page_num, $per_page);
    		$get_list = $this->db->get()->result_array();
    		//echo "<PrE>";print_r($get_list);die();
    		return $get_list;  
    	}

    In the code above we are fetching data for showing featured blogs on the blog page. Every blog will show its photo and first 200 chars of its content. Also, you can increase of decrease this count by changing this number. The output of this query will go like this:-

     

    How to get selected numbers of character from column using Codeigniter?

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: