首页 > 解决方案 > 如何通过将变量传递到 where 来选择数据库中的字段

问题描述

我有三个功能。第一个是插入工作正常的成员事务 public function process_newreceipt(){

    $Bank = $this->test_data->test_input($_POST["Bank"]);
    $Member = $this->test_data->test_input($_POST["Member"]);       
    $Amount = $this->test_data->test_input($_POST["Amount"]);       
            $phone = $this->mobileNo($Member);          
    $message='Thanks';      
    $insert=$this->receipt_model->new_receipt($Bank,$Member,$Amount,
    if($insert>= 1)  
    {  sendsms($phone,$message);            

      echo '<script type="text/javascript">alert("successful");</script>';
        redirect(base_url('index.php/Receipt/Receipt_Transactions')); 
    }
2nd function is to search mobileno to send sms to by the $member above     
 public function MobileNo($member){
      $Query= $this->db->query("SELECT MOBILE FROM MEMBERS WHERE 
       ID_NO=$member" ); $row = $query->row();
  $Phone=$row->mobile;            
  return $Phone;

     }   Third function is to send sms  sendsms($phone,$message);    which is called up there on insert success     

我希望现在很清楚。谢谢你们的快速回复

标签: phpcodeigniter

解决方案


// Use this method on codeigniter Model class and call this method in controller class

public function MobileNo($ID_NO)
{
    // if you are not load database first load database
        // $this->load->database();
    // With Method Chaining
    $query = $this->db->select( 'MOBILE')
                        ->where( 'ID_NO', $ID_NO)
                        ->get( 'MEMBERS');

    $result = $query->row();
    if($query->num_rows() > 0) {
        echo $result->MOBILE;
    }
    else{
        return false;
    }

}

推荐阅读