gpt4 book ai didi

php - Codeigniter 预订模块

转载 作者:行者123 更新时间:2023-11-29 11:02:08 24 4
gpt4 key购买 nike

所以我目前正在尝试为我们的类项目开发一个预订模块。我有一个预订表,其中有预订 ID、用户 ID、预订日期和预订时间。我的预订时间的值为“6”、“7”、“8”和“9”,表示预订的时间。在我的检查预订状态页面中,用户可以查看日期的状态以了解是否已预订什么时间。我的问题是如何正确输出保留状态?

例如:enter image description here

我有 02/05/2017 的多条记录,并且我使用了 foreach 循环。问题是,如果我使用 foreach,它将重复如下所示的行,而不是只显示一行。 enter image description here

期望的输出: enter image description here

这是我的代码。

Controller :

function court_one()
{
$data['date'] = date("Y/m/d");
$data['result'] = $this->model_reservation_user->getcourtone_defaultavailability();
$this->template->load('user_template', 'view_userreservation_courtone', $data);
}

function check_availability_courtone()
{
$searchquery = $this->input->get('search', TRUE);

if(isset($searchquery) and !empty($searchquery))
{
$data['date'] = $searchquery;
$data['result'] = $this->model_reservation_user->getcourtone_availability($searchquery);
$this->template->load('user_template', 'view_userreservation_courtone', $data);
}
else
{
redirect('user_reservation/court_one');
}
}

型号:

    function getcourtone_defaultavailability()
{
$query = $this->db->select('*')->from('courtone_reservation')->where('reservation_date', date("m/d/Y"))->get();

if($query->num_rows() > 0)
{
return $query->result();
}
else
{
return $query->result();
}
}

function getcourtone_availability($searchquery)
{
$query = $this->db->select('*')->from('courtone_reservation')->where('reservation_date', $searchquery)->get();

if($query->num_rows() > 0)
{
return $query->result();
}
else
{
return $query->result();
}
}

查看:

      <table class="table table-hover">
<tr>
<th><br>Date and Time Reserved</th>
<th><br>6:00-7:00</th>
<th><br>7:00-8:00</th>
<th><br>8:00-9:00</th>
<th><br>9:00-10:00</th>
</tr>

<?php foreach ($result as $result): ?>
<tr>
<td><?php echo date("F d, Y", strtotime($date)); ?></td>
<?php if($result == FALSE) { echo '<td class="vacant"></td>'; } else if($result->reservation_time == 6) { echo '<td class="reserved"></td>'; } else { echo '<td class="vacant"></td>'; } ?>
<?php if($result == FALSE) { echo '<td class="vacant"></td>'; } else if($result->reservation_time == 7) { echo '<td class="reserved"></td>'; } else { echo '<td class="vacant"></td>'; } ?>
<?php if($result == FALSE) { echo '<td class="vacant"></td>'; } else if($result->reservation_time == 8) { echo '<td class="reserved"></td>'; } else { echo '<td class="vacant"></td>'; } ?>
<?php if($result == FALSE) { echo '<td class="vacant"></td>'; } else if($result->reservation_time == 9) { echo '<td class="reserved"></td>'; } else { echo '<td class="vacant"></td>'; }?>
</tr>
<?php endforeach; ?>
</table>

最佳答案

这假设您只返回结果中包含多个小时的单个日期。

在你看来...

// Start table row
<tr><td><?php echo date("F d, Y", strtotime($date)); ?></td>

<?php
// Set an array of 10 'hour' switches
$tdX = array(0,0,0,0,0,0,0,0,0,0,0);

// loop through results setting the array switches
foreach ($result as $result)
$tdX[$result->reservation_time] = 1;
}

// loop through array building row
for ($i = 6; $i<=9; $i++) {

if ($tdX[$i] === 1 ) {
$tdClass = 'reserved';
} else {
$tdClass = 'vacant';
}

echo "<td class='$tdClass'></td>";

}

// close row
echo '</tr>';

关于php - Codeigniter 预订模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42053204/

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