调查结果显示为进度条

时间:2015-03-24 10:13:03

标签: php codeigniter progress survey onactivityresult

我有一项调查,我希望将结果显示为进度条。我已经完成了一个问题,但是当问题达到40以上时我不知道怎么做,我需要一些逻辑而不是编写很多代码。而且我必须以这种方式显示这些结果:如果你以5分的价格投票给问题1的例子,结果显示有多少人在同一问题上投了5分的百分比。这是我的模特:

<?php
class Result_model extends CI_Model {

    
    public function __construct() {
        parent:: __construct();
        $this->load->database();
         
    }
     
    public function total_rows()
    {
    	$query = $this->db->query("SELECT * FROM survey_answers ");
    		if($query->num_rows() > 0)
            {
                return $query->num_rows();
            } 
            else 
            {
                return false;
            }
    }
    public function result_question()
    {
    	$query = $this->db->query("SELECT * FROM survey_answers WHERE question_id = 3 ");
    		if($query->num_rows() > 0)
            {
                return $query->num_rows();
            } 
            else 
            {
                return false;
            }
    }

    




}
我的控制器:

 public function results_show()
    {
        $this->load->model('result_model'); 
        $data['total_rows'] =$this->result_model->total_rows();
        $data['result_question1'] = $this->result_model->result_question();
        $data['view'] = 'results';
        
        $this->load->view('templates/main',$data);  
    }

我的观点是:

<html>
<head>
</head>
<body>
<div class='col-md-8'>
<br/><br/>
<?php
$percentQuestion1 = ($result_question1 / $total_rows)*100;
?>

<ul>
	<br />
	<div class="progress">
    	<div class="progress-bar" role="progressbar" style="width: <?php echo round($percentQuestion1,2); ?>%;">
     		<?php echo round($percentQuestion1,2); ?>%
    	</div>
	</div>
			
</ul>

<h6>Total votes: <?php echo $total_rows ?></h6>
		
</div>
</body>
</html>

我的调查视图是:

<html>
<head>
</head>
<body>
<br/><br/>
<?php
$survey_id = $this->uri->segment(3);

	echo "<div class='col-md-9'>";

echo "<table border='0'>";   
echo validation_errors();

foreach ($survey as $row)
{
	echo "<tr>";
	echo form_open('index/survey_fill/' .$survey_id);
    echo "<td class='col-md-9'>"; 
	echo "$row->question";
	echo "<input type='hidden' name='question_id' value='$row->question_id' />";
	echo "</td>";
	if($this->session->userdata('role_id')==4) {
	 "</tr><tr><td>";  
	$data=array(
		'name' =>  'answer['.$row->question_id.']',
		'value' => '5'
	);
	  echo "<input type='hidden' name='survey_id' value='$row->survey_id'>";
	echo "<input type='hidden' name='question_id' value='$row->question_id' />";
	echo form_radio($data);
	echo " I like it very much ";
	$data=array(
		'name' =>  'answer['.$row->question_id.']',
		'value' => ' 4'
	);
	echo form_radio($data);
	echo " I like it ";
	$data=array(
		'name' => 'answer['.$row->question_id.']',
		'value' => ' 3'
	);
	echo form_radio($data);
	echo " I like it little ";
	$data=array(
		'name' => 'answer['.$row->question_id.']',
		'value' => '2'
	);
	echo form_radio($data);
	echo " I don't like ";
	$data=array(
		'name' => 'answer['.$row->question_id.']',
		'value' => '1'
	);
	echo form_radio($data);
	echo " I don't like at all ";
	echo "</td></tr><tr><td>";
  	
}

	$data=array(
		'name' => 'submit',
		'value' => 'Send',
		 'id' => 'survey_submit'
	);
	echo form_submit($data);
	echo "</td></tr>";
	echo form_close();
	echo "</table>";
	echo "</div>";
	echo "</body>";
	echo "</html>";

0 个答案:

没有答案