Php 具有Idiorm和Date问题的MySQL查询
我想在我的一些数据上使用图表,并根据所选日期(使用日期选择器)生成值。我偷了网上的大部分东西,可能只有一个简单的问题 以下是Idiorm查询:Php 具有Idiorm和Date问题的MySQL查询,php,mysql,sql,date,idiorm,Php,Mysql,Sql,Date,Idiorm,我想在我的一些数据上使用图表,并根据所选日期(使用日期选择器)生成值。我偷了网上的大部分东西,可能只有一个简单的问题 以下是Idiorm查询: if (isset($_GET['start']) AND isset($_GET['end'])) { $start = $_GET['start']; $end = $_GET['end']; $data = array(); // Select the results with Idiorm $results = ORM::for_table(
if (isset($_GET['start']) AND isset($_GET['end'])) {
$start = $_GET['start'];
$end = $_GET['end'];
$data = array();
// Select the results with Idiorm
$results = ORM::for_table('tbl_data')
->where_gte('date', $start)
->where_lte('date', $end)
->order_by_desc('date')
->find_array();
// Build a new array with the data
foreach ($results as $key => $value) {
$data[$key]['label'] = $value['date'];
$data[$key]['value'] = $value['rev'];
}
echo json_encode($data);
}
$start
和$end
来自我的日期选择器,格式为yyyy-mm-dd
。我唯一不知道怎么做的就是如何更改->wheregte
语句。如您所见,它正在数据库中查询字段date
。在我的数据库中有三个字段,年
,月
和日
是否有办法将三个字段年
、月
和日
组合成一个表达式,即可能->其中_gte('year'和'month'和'day',$start)
我尝试了一次又一次的搜索,但可能有错误的关键字或知识不足
提前感谢您的帮助 您可以使用MySql
date\u format()
函数管理日期格式。例如:
// Select the results with Idiorm
$results = ORM::for_table('tbl_data')
->where_gte('date', "DATE_FORMAT($start, '%Y-%m-%d')")
->where_lte('date', "DATE_FORMAT($end, '%Y-%m-%d')")
->order_by_desc('date')
->find_array();
由于数据库中有三个字段,因此需要三个
where_gte
子句:
...
->where_gte('year', substr($start, 0, 4) // or most suitable date_format
->where_gte('month', substr($start, 5, 2) // or most suitable date_format
...
希望有帮助。谢谢-但我的sql表中没有日期字段。我要找的是根据我的年、月和日的值创建一个日期。