0

データベースから値の ID を取得し、それを使用してアイテムを削除したいと考えています。私のコードは次のとおりです。

このコードは現在、データベースから一連のレコードを取得しており、各レコードにはリンクがあります。これどうやってするの?

<h2>List of all polls in this site:</h2>
<?php echo '<table>';?>
<table border="1">
  <tr>
    <th>Title</th>
    <th>Text</th>    

    <th colspan="2">Action</th>        
  </tr>
<?php 
foreach($polls as $polls_item){
  echo "<tr>";
    echo "<td>". $polls_item['title'] ."</td>";
    echo "<td>". $polls_item['text'] ."</td>";
    echo "<td>". anchor('user/vote/'.$polls_item->id,'Vote') ."</td>";
    echo "<td>". anchor('admin/del/'.$polls_item->id,'Delete') ."</td>";        
  echo "</tr>"; 
}
?>

<?php echo anchor('admin/del/1','Delete'); ?>

</table>
4

2 に答える 2

0

管理コントローラーがあり、最初にadmin_modelをロードしたと仮定します。これは、すべてのポーリングを取得する場所です。

class Admin
....
function del($id = null)
{
  $this->admin_model->delete($id);
} 

次に、admin_modelで、pollsはデータベースのテーブル名です。

class Admin_model
....
function delete($id)
{
 $this->db->delete('polls', array('id' => $id)); 
}

これが十分に明確であることを願っています。

于 2012-10-04T03:29:23.723 に答える
0

function del「管理者」コントローラーに次のものがあります。

function del($item_to_delete) 
 {
   $this->your_model->delete_item($item_to_delete);
 }

あなたのモデルで:

function delete_item($id)
 {
   $this->db->delete('mytable', array('id' => $id)); 
   // some successful message to return
 }

Codeigniter のドキュメントをご覧ください。

于 2012-10-04T03:38:17.057 に答える