数据库部分代码如下:
static function get_list_per_app($search_cond){
$list = array();
database::Connect($pdo);
$sql = "SELECT CLI.id_c client_id, CLI.name_c client_name, APP.id_c app_id, APP.name_c app_name,
(LSN.actual_minutes_c / 60* LSN.hourly_wage_c) lesson_wage, (APP.lesson_unit_price_c) lesson_sales,
(LSN.transportation_expenses_c) transportation_expenses
FROM lesson_t LSN
LEFT JOIN application_t APP ON APP.id_c = LSN.app_id_c
LEFT JOIN client_t CLI ON CLI.id_c = APP.client_id_c
where LSN.date_c >= '$search_cond->start_date' AND LSN.date_c <= '$search_cond->end_date' and CLI.department_c & ".$search_cond->department." AND
(LSN.state_c & ".(LSN_REPLACED+LSN_CLI_CANCELLED+LSN_TTR_CANCELLED+LSN_ADM_CANCELLED) ."= 0) AND APP.open_status_c & ".APP_OPST_OPEN_OR_PENDING." > 0;";
$del = $pdo->prepare($sql);
$del->execute();
while ($row = $del->fetch(PDO::FETCH_ASSOC))
{
if (empty($list[$row['app_id']])){
$infos = new stdClass();
$infos->client_name = '';
$infos->client_id = '';
$infos->app_name = '';
$infos->sales_of_lesson = 0;
$infos->sales_of_material = 0;
$infos->sales_of_assessment = 0;
$infos->cost_of_lesson = 0;
$infos->cost_of_material = 0;
$infos->cost_of_assessment = 0;
$infos->cost_of_commting = 0;
$list[$row['app_id']] = $infos;
}
$list[$row['app_id']]->client_name = $row["client_name"];
$list[$row['app_id']]->app_name = $row["app_name"];
$list[$row['app_id']]->app_id = $row["app_id"];
$list[$row['app_id']]->sales_of_lesson += $row["lesson_sales"];
$list[$row['app_id']]->cost_of_lesson += $row["lesson_wage"];
$list[$row['app_id']]->cost_of_commting += $row["transportation_expenses"];
}
报错信息 :
感谢大家的帮助解答.
打印$sql变量的值出来,执行一下看看报错原因,这部分条件语句错误:
(LSN.state_c & ".(LSN_REPLACED+LSN_CLI_CANCELLED+LSN_TTR_CANCELLED+LSN_ADM_CANCELLED) ."= 0) AND APP.open_status_c & ".APP_OPST_OPEN_OR_PENDING." > 0;";
语法错误吧,中间的双引号改单引号试试
$sql = "SELECT CLI.id_c client_id, CLI.name_c client_name, APP.id_c app_id, APP.name_c app_name,
(LSN.actual_minutes_c / 60* LSN.hourly_wage_c) lesson_wage, (APP.lesson_unit_price_c) lesson_sales,
(LSN.transportation_expenses_c) transportation_expenses
FROM lesson_t LSN
LEFT JOIN application_t APP ON APP.id_c = LSN.app_id_c
LEFT JOIN client_t CLI ON CLI.id_c = APP.client_id_c
where LSN.date_c >= '$search_cond->start_date' AND LSN.date_c <= '$search_cond->end_date' and CLI.department_c & '.$search_cond->department.' AND
(LSN.state_c & '.(LSN_REPLACED+LSN_CLI_CANCELLED+LSN_TTR_CANCELLED+LSN_ADM_CANCELLED) .'= 0) AND APP.open_status_c & '.APP_OPST_OPEN_OR_PENDING.' > 0;";