我试图从datepicker获取日期作为varchar来从我的SQL数据库中获取数据并显示表中的结果,但我的变量不能识别使用此代码。我的错误是"未定义的变量:数据"
我使用MVC作为我的框架,使用MsSql作为我的数据库。
模型
function srch_ecms()
{
$x = explode('.',$data['fromDate']);
//print_r ($data);
$qString = "";
$qString .= '[dbo].[SEARCH_ecms] '; //STORED PROCEDURE
$qString .= "'" .$data['fromDate']."'";
//echo $qString;
$query = $this->db->query($qString);
print_r($query->result());
return ($query->num_rows() > 0 ? $query->result() : NULL);
}
查看
<form method="post" action="<?php echo base_url(); ?>index.php/welcome/search_ecms">
<p>Select Date
</br>
From: <input type="text" name="fromDate" id="fromDate" /> To: <input type="text" name="toDate" id="toDate" /></p>
<input type="submit" value="Submit" name="dateData" id="dateData"/>
</form>
控制器
function search_ecms() {
$data['dateData']=$this->input->post('dateData');
$this->load->model('navi_model');
$query = $this->navi_model->srch_ecms();
$data['ecms'] = $query;
}
存储过程
@fileDate VARCHAR(20)
AS
BEGIN
SET NOCOUNT ON;
declare @tablesuffix varchar(10)
select @tablesuffix=upper(substring(datename(m,convert(datetime,@fileDate)),1,3))+convert(varchar,year(convert(datetime,@fileDate)))
print @tablesuffix
DECLARE @sqlCommand varchar(1000)
SET @sqlCommand = 'SELECT gen_048_' + @tablesuffix
EXEC (@sqlCommand)
END