0

我正在尝试从我拥有的主页中删除消息,当我按下删除按钮时,我收到一些 php 错误消息,说我声明的字段都无效,以及数据库错误 - 未知列'='消息'' 'where 子句'。我正在尝试不仅从主页删除消息,而且还从数据库中删除消息。我已经在我的messagesTable 数组中清楚地说明了from、to 和message 字段,为什么他们说无效?我的函数被称为delete($messageTable).

我的模型:

class Messages extends CI_Model
{

   private $messagesTable = 'messages'; 

   function Messages()
   {
      parent::__construct();
   }


   function addMessage($from, $to, $message)
   {
      $record = array(
        'to' => $to,
        'from' => $from,
        'message' => $message);
      $this->db->insert('messages', $record);   
   }


   function getMessages($user)
   {

      $this->db->select('*');
      $this->db->from('messages');
      //$this->db->where('to', $user);
      $messagesSet = $this->db->get();

      $messages = array ();

      foreach ($messagesSet->result() as $row)
      {
      $messages[] = array('from' => $row->from, 'message' => $row->message);

      } 

      return $messages;
   }


   function delete($messagesTable) {

      $messagesTable = array(
        $from  => 'from',
        $to  => 'to',
        $message => 'message');

          $this->db->select('*')->from('messages')->where($messagesTable);
          $this->db->delete($messagesTable);
    }

}

我的观点:

 <div id="maincontent">
  <div id="primary">     
    <h2> Friends </h2> 
    <ul> 
       <?php foreach ($friends['mutual'] as $name):?>
       <li> 
       <?=anchor("profile/view/$name", $name)?>, (<?=anchor("home/drop/$name", 'drop')?>)
       </li>
        <?php endforeach?>
     </ul>
   <h2> Following </h2> 
    <ul>
      <?php foreach($friends['following'] as $name):?>
        <li>  <?=anchor("profile/view/$name", $name)?>, (<?=anchor("home/drop/$name", 'drop')?>)</li>
      <?php endforeach?>
    </ul>
    <h2> Followers </h2> 
    <ul>
     <?php foreach($friends ['followers'] as $name):?>
        <li>
          <?=anchor("profile/view/$name", $name)?>
        </li>
      <?php endforeach?>
    </ul>
  </div>  
  <div id="secondary">
    <h2> Messages</h2> 
    <ul> 
      <?php foreach($messages as $message):?>
          <li><?=$message['from']?> says...: "<?=$message['message']?>"(<?=anchor("home/delete/{$message['from']}", 'delete')?>)</li>      
         <?php endforeach?>    
    </ul>      
  </div>
</div>

控制器:

 class Home extends CI_Controller 
 {
 function Home()
 {
 parent::__construct();
 $this->load->model('messages');
 $this->load->model('friends');
 $this->load->model("profiles");


 }

   function drop($member)
  {
   $username = $this->session->userdata('username');
   $this->friends->deleteFriend($username, $member);
   redirect('home');
  }



   function delete($messagesTable) {

$this->messages->delete($messagesTable);
$this->index();

    }


function index()
{

 $username = $this->session->userdata('username');
 $membername = $this->session->userdata('membername');
 $viewData['membername'] = $membername;
 $viewData['username'] = $username;
 $viewData['following'] = $this->friends->getFollowing($username);
 $viewData['followers'] = $this->friends->getFollowers($username);
 $viewData['messages'] = $this->messages->getMessages($membername);
 $viewData['friends'] = $this->friends->getFriends($username);


 $this->load->view('shared/header');
 $this->load->view('home/hometitle', $viewData);
 $this->load->view('shared/nav');
 $this->load->view('home/homeview', $viewData);
 $this->load->view('shared/footer');
}

  } 
4

1 回答 1

0

这不应该

$messagesTable = array(
    $from  => 'from',
    $to  => 'to',
    $message => 'message');

$messagesTable = array(
    'from'  => $from,
    'to'  => $to,
    'message' => $message);

??

于 2012-12-02T23:09:13.170 回答