Showing posts with label Sql. Show all posts
Showing posts with label Sql. Show all posts

Wednesday, 17 June 2020

count all with where condition in codeiginter sql

Model :
public function getRowcountCardGallery($id){
       
        return $this->db->where('card_id',(int)$id)->from("card_gallery")->count_all_results();
    }

Controller :
$data['rowcount']=$this->Myaccount_model->getRowcountCardGallery($id);

View : 
<?php if(isset($rowcount) && $rowcount!=''){
   
    echo $rowcount;

}


?>

Thursday, 28 May 2020

Get Parent Id name in same table

Get same table id to parentid name


SQL : 

$sql=$this->db->query("SELECT a.id, a.name, a.sorder, a.isactive, b.name AS 'ParentName' FROM category AS a LEFT JOIN category AS b on a.parentid = b.id  where a.parentid!='0' order by a.parentid asc ");

return $sql->result();