【发布时间】:2015-06-09 11:05:26
【问题描述】:
我正在尝试使用 codeigniter 框架在 php 中开发搜索功能。它应该也可以使用时间和大厅进行搜索。当我只使用时间时它可以工作。但是当我使用大厅时它会变得非常错误。下面我附上了我正在使用的所有代码。
我将模型分为模型和服务两部分。在模型中有 getter 和 setter。在服务类中,我只写查询。如果有人能给我一个肯定的答案,那将非常有帮助。提前致谢。
模型(reservation_service.php)
function search_reservations($time,$hall) {
$this->db->select('reservations.*');
$this->db->from('reservations');
$this->db->like('time', $time);
$this->db->or_like('hall',$hall);
$this->db->where('is_deleted', '0');
$query = $this->db->get();
return $query->result();
}
控制器(dashboard.php)
function search_results() {
$reservation_service = new Reservation_service();
$time_booking = trim($this->input->post('time', TRUE));
$hall_booking = trim($this->input->post('hall', TRUE));
$data['search_results'] = $reservation_service->search_reservations($time_booking,$hall_booking);
$partials = array('content' => 'dashboard/search_results');
$this->template->load('template/main_template', $partials, $data);
}
function search_reservations() {
$reservation_service = new Reservation_service();
$data['search_results'] = $reservation_service->search_reservations(trim($this->input->post('time', TRUE)));
$partials = array('content' => 'dashboard/reservation_report');
$this->template->load('template/main_template', $partials, $data);
}
查看
reservation_report.php
<div class="form-group"><br>
<input id="time" name="time" type="text" placeholder="Time Slot">
<input id="hall" name="hall" type="text" placeholder="Hall">
<button class="btn btn-primary" onclick="search()" >Search</button>
</div>
<div id="search_results">
<?php echo $this->load->view('dashboard/search_results'); ?>
</div>
<script type="text/javascript">
function search() {
var time = $('#time').val();
$.ajax({
type: "POST",
url: '<?php echo site_url(); ?>/dashboard/search_results',
data: "time=" + time,
success: function(msg) {
$('#search_results').html(msg);
}
});
}
</script>
search_results.php
<div class="adv-table">
<table class="display table table-bordered table-striped" id="bookings_table">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Hall</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($search_results as $result) {
?>
<tr id="bookings_<?php echo $result->id; ?>">
<td><?php echo ++$i; ?></td>
<td><?php echo $result->date; ?></td>
<td><?php echo $result->hall; ?></td>
<td><?php echo $result->time; ?></td>
<?php } ?>
</tbody>
</table>
</div>
【问题讨论】:
-
什么问题,请具体说明。
-
您使用的是哪个 codeigniter 版本?使用一次 or_where 而不是 or_like。
标签: php html codeigniter