我无法删除我的主页上留下的消息,以便从我的消息db和主页本身中删除

时间:2012-12-02 22:48:08

标签: php codeigniter

我正在尝试从我拥有的主页中删除邮件,当我按下删除按钮时,我收到一些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');
}

  } 

1 个答案:

答案 0 :(得分:0)

不应该这个

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

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

...