gpt4 book ai didi

php - codeigniter mysql查询输出数据显示特定条件

转载 作者:行者123 更新时间:2023-11-29 13:10:07 25 4
gpt4 key购买 nike

以下代码:

Controller .php

function getchart() {
$prac = $this->input->post('prac_name');
$datee = $this->input->post('datee');
$this->load->model('appoint');
$results['appoint'] = $this->appoint->getappoint($prac , $datee);
$this->load->view('ajax/getappchart' , $results);
}

模型.php

function getappoint($prac , $datee) {
$this->db->select('rdv.id as rdvid, startTime, endTime, day, firstname, lastname');
$this->db->from('rdv');
$this->db->join('contact', 'contact.id = rdv.contact_id');
$this->db->where('people_id',$practicien);
$this->db->where('DATE(day)', $datee);
$this->db->order_by('TIME(startTime)', 'ASC');
$query = $this->db->get();
//print_r($this->db->last_query());
return $query;
}

查看.php

if ($appoint->num_rows() > 0) {
foreach($appoint->result() as $sub_row)
{
// display output.
}
} else {
echo 'No Appointments on Above Date.';
}
?>

我需要的是,有相同时间和日期的约会(大部分是2个相同的)。如果超过2个,我需要为两个约会设置两种不同的类(class)风格。我怎样才能实现这个目标?

谢谢。

最佳答案

最终答案:在@minhaz-ahmed的帮助下完成

if ($appoint->num_rows() > 0) {
$appoint_counter = array();
foreach ($appoint->result() as $sub_row) {
//i am assuming your startTime is H:M:S, and day Y-M-D format
$key = strtotime($sub_row['day'] . ' ' . $sub_row['startTime']);
if (!isset($appoint_counter[$key])) {
$appoint_counter[$key] = 0;
}
$appoint_counter[$key] ++;
$style_class = 'YOUR_1ST_CLASS';
if ($appoint_counter[$key] > 2) {
$style_class = 'YOUR_2ND_CLASS';
}

//REST VIEW CODE
}
}
else {
echo 'No Appointments on Above Date.';
}

关于php - codeigniter mysql查询输出数据显示特定条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22207148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com