2017-10-15 49 views
0

参数没有传递给模型,所以sql查询不会产生结果。它什么也没有显示,甚至没有错误。为什么没有参数传递到模型?在数据库中的SQL查询工作正常时,变量之前的日期是忽略了时间,因为在数据库中的字段是datetime类型的你为什么不传递参数?

控制器

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

    $this->load->model('M_Login'); 
    $this->load->model('M_Porcentaje'); 


} 

public function tabla_porcentaje(){ 


$fecha_ini = $this->input->post('fecha_ini'); 
$fecha_ter = $this->input->post('fecha_ter'); 



$data['consulta'] = $this->M_Porcentaje->tabla_porcentaje($fecha_ini, $fecha_ter); 
$this->load->view('usuarios/test.php',$data); 


} 

型号

public function tabla_porcentaje ($fecha_ini, $fecha_ter){ 



$this->db->select("motivos_citas.descripcion_mot,COUNT(*) AS cantidad_motivos, (SELECT COUNT(motivos_citas.descripcion_mot)* 100/COUNT(citas.id_ci) FROM citas AS citas WHERE date(citas.fecha_ini) BETWEEN date('$fecha_ini') AND date('$fecha_ter')) AS porcentaje"); 
$this->db->from("citas"); 
$this->db->join("motivos_citas","citas.id_mot=motivos_citas.id_mot"); 
$this->db->where("date(citas.fecha_ini) BETWEEN date('$fecha_ini') AND date('$fecha_ter') "); 
$this->db->group_by("motivos_citas.descripcion_mot"); 
$consulta = $this->db->get(); 

return $consulta->result(); 
} 

AJAX

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

$("#btn_buscar").click(function(evento){ 


var fecha_ini = $("#fecha_ini").val(); 
var fecha_ter = $("#fecha_ter").val(); 

$.ajax({ 

    url: "<?php echo base_url();?>C_Porcentaje/tabla_porcentaje/", 
    type: 'post', 
    data: { "fecha_ini": fecha_ini, "fecha_ter": fecha_ter }, 

    success: function(response){ 

     alert($("#fecha_ini").val()); 
     alert($("#fecha_ter").val()); 
     window.open('<?php echo base_url();?>C_Porcentaje/tabla_porcentaje/', '_blank'); 
    } 

    }); 

    }); 

    }); 
</script> 
+0

被称为成功处理程序? –

+0

看看您在浏览器开发者控制台也为它可能是吐出的任何错误。如果是他们,请添加到您的文章。 – IncredibleHat

+0

成功不叫 – CristianOx21

回答

0

你绑定不好。您应该使用:

的$(document)。在( '点击', '#buscar',函数(URL){

+0

这不起作用,只需添加$(document).on (函数(){等,我不知道你的意思是 – CristianOx21

+0

是的,我参考了这个http://api.jquery.com/on/ –

+0

你应该在点击事件后立即发出警告,看看它是否触发。 –

0

尝试使用json_decode(file_get_contents("php://input"))而非$this->input->post()如果控制器将读取的数据。

public function tabla_porcentaje(){ 

    $input_post = json_decode(file_get_contents("php://input")); 

    $data = array (
    'fecha_ini' => $input_post->fecha_ini, 
    'fecha_ter' => $input_post->fecha_ter 
); 

    $this->load->model('M_Porcentaje_PDF'); 
    $this->M_Porcentaje_PDF->tabla_porcentaje($data); 

} 
+0

无法正常工作,感谢您的回复 – CristianOx21

相关问题