【发布时间】:2015-05-19 19:08:40
【问题描述】:
我有两张桌子
已注册的事件和事件,但我想显示按下按钮时它会将事件从事件中删除为已注册的事件。 但我无法删除事件本身 我可以隐藏它,使它不会出现在网页的表格中吗??
我正在使用 CodeIgniter
![Cassey 的 Graded Scratch Races 活动在两个表格中] [1]
我没有 10 声望,所以这里有一个图片链接 https://www.dropbox.com/s/uzyvblmim0e1s5v/2015-05-19%2013_13_00-Eastern%20Veterans%20Cycling.png?dl=0
型号
function getAll()
{
// get all the records from the schools table
$this->db->select('*');
$this->db->from('tblMeetRace as met');
$this->db->join('tblLocation as loc', 'loc.intLocationID = met.intLocationID');
$this->db->join('tblEvent as eve', 'eve.intEventID = met.intEventID');
//$this->db->Where('intMemberID = 1' );
$query = $this->db->get();
// if the number of rows returned is more than 0
if( $query->num_rows() > 0) {
// loop through each record (row) and place that
// record into an array called $data
foreach ($query->result() as $row) {
$data[] = $row;
}
}
$query->free_result();
// return the array to the controller
return $data;
function getAll1()
{
// get all the records from the schools table
$this->db->select('*');
$this->db->from('tblMeetRace as met');
$this->db->join('tblLocation as loc', 'loc.intLocationID = met.intLocationID');
$this->db->join('tblRegistration as reg', 'reg.intMeetRaceID = met.intMeetRaceID');
$this->db->join('tblEvent as eve', 'eve.intEventID = met.intEventID');
$this->db->Where('intMemberID = 1' );
$query = $this->db->get();
// if the number of rows returned is more than 0
if( $query->num_rows() > 0) {
// loop through each record (row) and place that
// record into an array called $data
foreach ($query->result() as $row1) {
$data1[] = $row1;
}
}
$query->free_result();
// return the array to the controller
return $data1;
}
控制器
public function getallevents() {
$this->load->model('events_model');
$data['records'] = $this->events_model->getAll();
$data1['records1'] = $this->events_model->getAll1();
$data3 = $data + $data1;
$this->load->view('view-events', $data3);
}
查看
<!-- code for table of schools -->
<div class="container proper-content">
<div class="bs-example table-responsive">
<h3>Unregistered Events</h3>
<table class="table table-striped table-bordered table-hover">
<thead class="tablebackground">
<tr>
<th> Meet race ID</th>
<th> Event Name</th>
<th> Location</th>
<th> Date</th>
<th> Time</th>
<th> Register</th>
</tr>
</thead>
<tbody>
<?php
foreach ($records as $row):
echo "<tr>";
echo "<td> $row->intMeetRaceID</td>";
//echo "<td> $row->intEventID</td>";
echo "<td> $row->strEventDescription</td>";
echo "<td> $row->strLocationName</td>";
echo "<td> $row->datDate</td>";
echo "<td> $row->timTime</td>";
echo "<td><a class='btn btn-success btn-sm'>Register</a></td>";
echo "</tr>";
endforeach;
?>
</tbody>
</table>
<h3>Registered Events</h3>
<table class="table table-striped table-bordered table-hover">
<thead class="tablebackground">
<tr>
<!-- <th> User-ID #</th> -->
<th> Event Name</th>
<th> Location</th>
<th> Date</th>
<th> Time</th>
<th> UnRegister</th>
</tr>
</thead>
<tbody>
<?php
foreach ($records1 as $row1):
echo "<tr>";
//echo "<td> $row->intMemberID</td>";
//echo "<td> $row1->intEventID</td>";
echo "<td> $row1->strEventDescription</td>";
echo "<td> $row1->strLocationName</td>";
echo "<td> $row1->datDate</td>";
echo "<td> $row1->timTime</td>";
echo "<td><a class='btn btn-danger btn-sm'>Delete</a></td>";
echo "</tr>";
endforeach;
【问题讨论】:
-
为什么有两张桌子?保存所有数据的单个表将绰绰有余。只需添加一个注册字段,其值为 0/1 或 Y/N。那么切换这个标志就很简单了。
-
这只是我的例子,我还有其他表格和其他信息
-
在程序中思考。您需要读取一个,删除它,然后将其写入另一个,但是如果您想确保它在那里,您可以做一个 where 以确保每个字段都匹配。
-
触发器怎么样?
标签: php html mysql sql codeigniter