Monday, 20 January 2020

select in codeigniter

public function getOneNewsCategory($id){
$sql=$this->db->query("SELECT * FROM `news_category`  where id='".(int)$id."' ");
return $sql->row();
}

delete in codeigniter

public function deleteNewsCategory($id){

$sql=$this->db->query("DELETE FROM `news_category` WHERE  id='".(int)$id."'");

return $sql;

}

update in codeigniter

public function updateNewsCategory($id,$image){

$sql=$this->db->query("UPDATE `news_category` SET

`name`='".$this->db->escape_str($this->input->post('name'))."',
`mobile`='".$this->db->escape_str($this->input->post('mobile'))."',
`detail`='".$this->db->escape_str($this->input->post('detail'))."',
    `created_dt`=Now(),
`isactive`='".$this->db->escape_str($this->input->post('isactive'))."'
WHERE id='".(int)$id."'");


return $sql;
}

Email send in Codeigniter

$from_email = "domin.help24@gmail.com";
        //$to_email = $this->input->post('email');
        $to_email = 'in.mukeshsaini@gmail.com';

        $subject = "All Free : Product Enquiry";

$message = "<h1>All Free : Enquiry</h1>";
$message .= "<b>Product : ".$this->input->post('code')."</b><br/>";
$message .= "<b>Name : ".$this->input->post('name')."</b><br/>";
$message .= "<b>Email : ".$this->input->post('email')."</b><br/>";
$message .= "<b>Phone: ".$this->input->post('phone')."</b><br/>";
$message .= "<b>Country: ".$this->input->post('country')."</b><br/>";
$message .= "<b>Description : </b><br/>";
$message .= "".$this->input->post('description')."";

$header = "From:".$this->input->post('email')." \r\n";
$header1 = "MIME-Version: 1.0\r\n";
$header2 = "Content-type: text/html\r\n";

        //Load email library
        $this->load->library('email');
        $this->email->from($from_email, 'Identification');
        $this->email->to($to_email);
        $this->email->cc('domin.help24@gmail.com');


        $this->email->subject($subject);
        $this->email->message($message);
       

        $this->email->set_header('MIME-Version', '1.0; charset=utf-8');
        $this->email->set_header('Content-type', 'text/html');


        //Send mail
        if($this->email->send()){
            $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
        }
        else{
            $this->session->set_flashdata("email_sent","You have encountered an error");
        }

data insert incodeigniter

public function savecardform(){



     
$sql=$this->db->query("INSERT INTO `card` (`location`,`category`,`business`, `name`, `mobile`,`mobile1`, `mobilew`,`landline`,`email`, `tagline`, `gstno`, `landmark`,`address`,`village`,`city`,`pincode`,`state`,`businesspet`,`service`,`timetable`,`about`, `created_dt`, `updated_dt`, `isactive`)
VALUES (
'".$this->db->escape_str($this->input->post('location'))."',
'".$this->db->escape_str($this->input->post('category'))."',
'".$this->db->escape_str($this->input->post('business'))."',
'".$this->db->escape_str($this->input->post('name'))."',
'".$this->db->escape_str($this->input->post('mobile'))."',
'".$this->db->escape_str($this->input->post('mobile1'))."',
'".$this->db->escape_str($this->input->post('mobilew'))."',
'".$this->db->escape_str($this->input->post('landline'))."',
'".$this->db->escape_str($this->input->post('email'))."',
'".$this->db->escape_str($this->input->post('tagline'))."',
'".$this->db->escape_str($this->input->post('gstno'))."',
'".$this->db->escape_str($this->input->post('landmark'))."',
'".$this->db->escape_str($this->input->post('address'))."',
'".$this->db->escape_str($this->input->post('village'))."',
'".$this->db->escape_str($this->input->post('city'))."',
'".$this->db->escape_str($this->input->post('pincode'))."',
'".$this->db->escape_str($this->input->post('state'))."',
'".$this->db->escape_str($this->input->post('businesspet'))."',
'".$this->db->escape_str($this->input->post('service'))."',
'".$this->db->escape_str($this->input->post('timetable'))."',
'".$this->db->escape_str($this->input->post('about'))."',
            Now(),
            Now(),
'0'
)");
return $sql;



}

lazy loader in Codeigniter

View : 

<section class="cardlist" id="results">
            <div id="load_data"></div>
            <div id="load_data_message"></div>
</section>


<script>
  $(document).ready(function(){

    var limit = 4;
    var start = 0;
    var action = 'inactive';

    function lazzy_loader(limit)
    {
      var output = '';
      for(var count=0; count<limit; count++)
      {
        output += '<center> <div class="loading-info"><img src="<?php echo base_url().'assets/front/'?>images/loading.gif" /></div></center>';

      }
      $('#load_data_message').html(output);
    }

    lazzy_loader(limit);

    function load_data(limit, start)
    {

      $.ajax({
        url:"<?php echo base_url(); ?>Web/cardFetch",
        method:"GET",
        data:{limit:limit, start:start},
        cache: false,
        success:function(data)
        {
          if(data == '')
          {
            $('#load_data_message').html('<center><h5 style="color: green;"> No More Card Available </h5></center>');
            action = 'active';
          }
          else
          {
            $('#load_data').append(data);
            $('#load_data_message').html("<center><h4 style='color: red;'> No More Card Available </h4></center>");
            action = 'inactive';
          }
        }
      })
    }

    if(action == 'inactive')
    {
      action = 'active';
      load_data(limit, start);
    }

    $(window).scroll(function(){
      if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
      {
        lazzy_loader(limit);
        action = 'active';
        start = start + limit;
        setTimeout(function(){
          load_data(limit, start);
        }, 1000);
      }
    });

  });
</script>


Controller : 





public function cardlist()
{
if($this->uri->segment('3')!=''){
$this->session->set_userdata('src_category', $this->uri->segment('3'));
}

if($this->input->post('src_text')!=''){
$this->session->set_userdata('src_text', $this->input->post('src_text'));
}else{
$this->session->set_userdata('src_text','');
}


$data=array();
$data['CardList']=$this->Web_model->getCardList();
$data['CategoryName']=$this->Web_model->getCategoryName();
$data['LocationName']=$this->Web_model->getLocationName();
$data['ads_list_top_ads']=$this->Web_model->getadsData('list_top_ads');
$data['ads_list_footer_ads']=$this->Web_model->getadsData('list_footer_ads');
$this->load->view('front/card_list',$data);
}

function cardFetch()
{
$output = '';
$this->load->model('Web_model');
$data = $this->Web_model->fetch_data($this->input->get('limit'), $this->input->get('start'));
if($data->num_rows() > 0)
{
$bg=1;
            $i=1;
foreach($data->result() as $val)
{
if($val->verified=='1'){  $verifiedPhoto = '<img src="'.base_url('assets/front/icon/verified.png').'"  class="verified" />'; }else{ $verifiedPhoto=''; }


                if($val->path1!=''){
                   $ownerPhoto ='<img src="'.base_url('upload/card/').''.$val->path1.'" class="owner" />';
                      }else{
                  $ownerPhoto ='<img src="'.base_url('assets/front/icon/logoshort.jpg').' " class="owner" />';
                 }



$output .= '
<span class="cardlistitem bg'.$bg++.'">
           
    '.$verifiedPhoto.'         
    <a href="'.base_url('web/detail/').''.$val->id.''.$this->uri->segment('3').'">
       
        <table>
            <tr>
                <td width="25%">
                   '.$ownerPhoto.'
                </td>
                <td width="75%">
        <table style="margin: 5px;">
            <tr><th><span class="t1">'.ucwords( $val->business ).'</span> </th></tr>
            <tr><th><span class="t2"><img src="'.base_url('/assets/front/icon/user.png').'" class="sicon" />'.ucwords( $val->name ).'</span> </th></tr>
            <tr><th><span class="t2"><img src="'.base_url('/assets/front/icon/mobile.png').'" class="sicon" />'.$val->mobile.'</span> </th></tr>     
            <tr><th><span class="t2"><img src="'.base_url('/assets/front/icon/s.png').'" class="sicon" style="background-color: #fff; " />'.substr($val->service,0,26).'</span> </th></tr>   
        </table>
            </td>
            </tr>

            <tr><td colspan="2"><span class="t4">'.ucfirst( $val->address ).'</span></td></tr>
        </table>


    </a>
</span>';



}
}
echo $output;
}




Models : 




function fetch_data($limit, $start)
{

            $src_location = $this->session->userdata('src_location');
            $src_category = $this->session->userdata('src_category');


     
    $src_text = $this->db->escape_str($this->session->userdata('src_text'));

$this->db->select("*");
$this->db->from("card");
if($src_text==''){
    $this->db->where(" category='".$src_category."' && location='".$src_location."' &&  isactive='1' ");              
}else{
      $this->db->where(" category='".$src_category."' && location='".$src_location."' && isactive='1'  && ( business LIKE '%".$src_text."%'  ||  name LIKE '%".$src_text."%' || address LIKE '%".$src_text."%' || mobile LIKE '%".$src_text."%' || service LIKE '%".$src_text."%') ");                      
}

$this->db->order_by("plan", "DESC");
$this->db->limit($limit, $start);
$query = $this->db->get();
return $query;
}





password encode codeigniter


$password=hash("sha256", $this->input->post('pass'));



Form validation in codeigniter


Form Validation ---------------------------------

Type : 

'trim|required|min_length[5]|max_length[12]|valid_email|xss_clean|matches[passconf]|is_unique[table.field]'


$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[8]|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('email', 'email', 'required|trim|valid_email|xss_clean');

$this->form_validation->set_rules('username', 'User Name', 'required|trim');
$this->form_validation->set_rules('pass', 'Password', 'required|trim');
if ($this->form_validation->run() == FALSE) {

redirect("administration/home");
}else{

}



More Information validation Rules
https://www.tutorialspoint.com/codeigniter/codeigniter_form_validation.htm