2015-05-19 30 views
0

我有2個表刪除一行時,它被添加到不同的表

登記的活動和事件,但我想,當按下按鈕它會從事件到註冊事件的事件顯示。 但我無法刪除事件本身 我可以隱藏它,所以它不會出現在網頁上的表?

我使用笨

![在Cassey發佈領域分級劃痕種族事件是兩個表中] [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>&nbsp;&nbsp;Meet race ID</th> 
        <th>&nbsp;&nbsp;Event Name</th> 
        <th>&nbsp;&nbsp;Location</th> 
        <th>&nbsp;&nbsp;Date</th> 
        <th>&nbsp;&nbsp;Time</th> 
        <th>&nbsp;&nbsp;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>&nbsp;&nbsp;User-ID #</th> --> 
        <th>&nbsp;&nbsp;Event Name</th> 
        <th>&nbsp;&nbsp;Location</th> 
        <th>&nbsp;&nbsp;Date</th> 
        <th>&nbsp;&nbsp;Time</th> 
        <th>&nbsp;&nbsp;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; 
+1

爲什麼有2個表?保存所有數據的單個表格就足夠了。只需添加一個值爲0/1或Y/N的字段。然後這將是一個簡單的事情,切換此標誌。 – jeff

+0

這只是我的例子,我也有其他表格和其他信息 – user2398718

+0

在程序中思考。你需要閱讀一個,刪除它,然後寫到另一個,但如果你想確保它在那裏,你可以做一個確保每個字段匹配的位置。 –

回答

0

儘管你可以做這個事情變得簡單了很多,你可以嘗試擴展您的第一個查詢這樣的 - 如果我理解正確的話:

$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->join('tblRegistration as reg', 'reg.intMeetRaceID = met.intMeetRaceID', 'left'); 
$this->db->where(array("met.intMeetRaceID" => NULL)); 
相關問題