php - 如何通过将变量传递到 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
我希望现在很清楚。谢谢你们的快速回复
解决方案
// 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;
}
}
推荐阅读
- google-cloud-firestore - 使用“in”查询构建社交时间线?
- node.js - 从邮递员发送数组并在 Node JS 中使用 express 验证器进行验证
- excel - 基于左侧单元格值的条件格式
- java - 线程“主”java.lang.UnsatisfiedLinkError 中的异常:'void org.lwjgl.opengl.WindowsDisplay.setWindowProc(java.lang.reflect.Method)'
- php - 删除调用 curl 返回 400
- python - 如何将kivy小部件推到屏幕顶部
- angular - ngIf 中的异步管道仍然获得价值
- javascript - 在 Javascript 数组中结合 indexOf 和 regexp 匹配
- android - 如何通过扫描条码获取信息?
- ios - 如何从 Firebase 实时数据库中解码数据