Welcome Guest, Not a member yet? Register   Sign In
Candidate Vote by Selected ID
#1

Hai, i want to create vote candidate by selected ID. i already create function, when select the first candidate and i want to change to other candidate it always show the first candidate that im click first, it wont selected by candidate that im choosed. Can someone help me to create the function to selected the candidate by their id to vote?

My Model

Code:
<?php

class Admin_dcalon extends CI_Model{
    

    
    function tampil_data(){
        $this->db->select('*');
        $this->db->from('calon');
        return $this->db->get();
    }
    
    
    
    function tambah_data($data,$table){
        $this->db->insert($table,$data);
    }
    
    function hapus_data($where,$table){
    $this->db->where($where);
    $this->db->delete($table);
    }
    
    function edit_data($where,$table){        
    return $this->db->get_where($table,$where);
    }
    
    function update_data($where,$data,$table){
        $this->db->where($where);
        $this->db->update($table,$data);
    }
    
    function vote_calon($where,$table)
    {
           return $this->db->get_where($table,$where);
        
    }
    
    

    function add_vote($where,$table){
        $this->db->from('calon'); //table
       $this->db->where($where);
        $this->db->set('voted', 'voted+1', FALSE);
        $this->db->update($table,$data,$where);
    }
    
    
}

?>

My Controller


Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


class Admin_calon extends CI_Controller
{

   function __construct() {
       parent::__construct();

     
       
        $this->load->model('Admin_dcalon');
        $this->load->model('Admin_dvoter');
        $this->load->model('Voter_model');
        $this->load->helper('url');
        $this->load->database();
     
   }

   public function index() {
        $data['calon'] = $this->Admin_dcalon->tampil_data()->result();
       $this->load->view('Admin_calon',$data);
        
   }
    
    function tambah_calon(){
        $nama = $this->input->post('nama');
        
                $config['upload_path'] = base_url(). './uploads/';
               $config['allowed_types'] = 'jpg|png|jpeg';
               $config['max_size'] = '0';
                
                $this->load->library('upload', $config);
               $this->upload->initialize($config);
               $this->upload->do_upload();
                
        $img = $this->input->post('img');
        

        $data = array(
            'nama' => $nama,
            'img' => $img,
            'voted' => 0
            );
        $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Data Tersimpan</div>');
        $this->Admin_dcalon->tambah_data($data,'calon');
        redirect('Admin_calon');
    }
    
    
    public function delete_calon($id_calon){
        $where = array('id_calon' => $id_calon);
        $this->Admin_dcalon->hapus_data($where,'calon');
         $this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Data Terhapus</div>');
        redirect('Admin_calon');
    }

    function edit_calon($id_calon){
        
        $where = array('id_calon' => $id_calon);
        $data['calon'] = $this->Admin_dcalon->edit_data($where,'calon')->result();
        $this->load->view('Admin_ecalon',$data);
    }
    
    function update_calon(){
    $id_calon = $this->input->post('id_calon');
    $nama = $this->input->post('nama');
    $img = $this->input->post('img');

    $data = array(
        'nama' => $nama,
        'img' => $img,        
    );

    $where = array(
        'id_calon' => $id_calon
    );
    $this->session->set_flashdata('msg','<div class="alert alert-info text-center">Perubahan Tersimpan</div>');
    $this->Admin_dcalon->update_data($where,$data,'calon');
    redirect('Admin_calon');
}

    function vote_calon($id_calon){
        $where = array('id_calon'=>$id_calon);
        $data['calon'] = $this->Admin_dcalon->vote_calon($where,'calon')->result();
        $this->load->view('voter/vote_calon',$data);
    }

    function add_vote($id_calon)
    {
        $id_calon = $this->input->post('id_calon');
        $voted = $this->input->post('voted');


        $data = array(
            'id_calon'=> $id_calon,
            'voted' => $voted        
        );

            $where = array(
            'id_calon' => $id_calon
            );

            $this->Admin_dcalon->add_vote($where,'calon');
            redirect('voter/voter_sukses');                    
    
    }
   
    
    
    
    
}
?>

My View ( on User )


Code:
<!doctype html>
<html>


<head>
       <title>Vote Kepala Desa</title>
       <link href="<?php echo base_url('asset/bootstrap/css/style.css');?>" rel="stylesheet">
       <link href="<?php echo base_url('asset/bootstrap/css/bootstrap.min.css');?>" rel="stylesheet">
        <link href="<?php echo base_url('asset/bootstrap/css/sb-admin.css');?>" rel="stylesheet">
        <link href="../../../asset/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css">
       
   
   </head>


<body style="font-family:'Segoe UI Light'">
   
       <!-- Navigation -->
       <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
           <!-- Brand and toggle get grouped for better mobile display -->
           <div class="navbar-header">
           </div>
           <!-- Top Menu Items -->
           <ul class="nav navbar-left top-nav">
               
               <li class="active">
                       <a href="<?= site_url('voter/voter_home') ?>"><i class="fa fa-fw fa-dashboard"></i>Home</a>
                   </li>
                   <li>
                       <a href="<?= site_url('voter/voter_vote') ?>" ><i class="fa fa-fw fa-bar-chart-o"></i>Vote</a>
                   </li>
                   <li>
                       <a href="<?= site_url('voter/voter_hasil') ?>" ><i class="fa fa-fw fa-bar-chart-o"></i>Hasil Voting</a>
                   </li>
           </ul>
           
           <ul class="nav navbar-right top-nav">
               
               
                       <li>
                   <a style="float:right" href="<?= site_url('voter/voter_home/logout') ?>">Logout</a>
                   
                       </li>
           </ul>
     
       </nav>
       
       
       
       
          
       
   
        <center>
                   <div class="col-lg-12" style="float:inherit">
                   
                    <div class="panel panel-default panel-profile m-b-0">
                    <div class="panel-heading" ></div>
                               
                               <div class="panel-body text-center" >
                                     <img src="<?php echo base_url('asset/img/certificate.png');?>" height="200" width="200">
                       

                       <h1><strong>Vote Calon Kepala Desa</strong></h1>
                       <p><strong>Sistem E-voting Desa Pakraman Cucukan</strong></p>
                       <img src="<?php echo base_url('asset/img/bookmark.png');?>" height="50" width="50">
                           
                           <br>
                           <br>
                           <center>
                           <h5 class="alert alert-danger">
                           <strong>PERHATIAN ! VOTE HANYA DAPAT DILAKUKAN 1X ( SATU KALI )</strong></h5>
                           </center>        
       <?php
        foreach($calon as $calon){
        ?>                            
                               
      <form class="" action="<?php echo site_url('admin_calon/vote_calon/'.$calon->id_calon);?>" method="post"   ?>
       
                          <input type="hidden" name="id_calon" value="<?php echo $calon->id_calon ?>">
                         
                       
     
        <div class="col-lg-4" action=""  method="post">
       
             <div class="panel panel-default panel-profile m-b-0">
            <div class="panel-heading" ></div>
                       <br>
                       <img class="img-circle img-thumbnail" style="width:200px;height:200px" src="<?php echo  base_url('upload/'.$calon->img) ?>">
                       <h4><strong>Calon <?php echo $calon->id_calon ?></strong></h4>
                       <h5><?php echo $calon->nama ?></h5>
                       <br>
                        
                       <button class="btn btn-lg btn-success" type="submit" >Vote</button>
                        </img>    
                         <br>
                         <br>
            </div>
        </div>
                <?php } ?>
       

       </form>
                                     
                               
                               
                               
                       </div>
                     </div>
                 
                 </div>
      </center>
               
       

</body>

</html>

Thanks for any help, sorry if my english is bad, hope you understand what i mean. 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB