如何在Codeigniter中使用getRecored_row方法从数据库中获取另一列值-有谁可以帮助我

时间:2018-12-17 08:38:26

标签: database codeigniter

我想使用CodeIgniter中的getRecored_row()方法从数据库中获取另一个列值,此后,我想使用landline_no列进行验证,但是从用户那里我们得到了唯一的电话号码,我们也要验证座机号码。这是我完成的代码。我被困在如何验证landline_no列中,phone_no已被验证。用户给出的数字还必须通过landline_no进行验证,以便如果已经存在该数字,它将显示 strong text (该文本已经存在)。

public function checklead() {
    $lead = $_POST['number'];//from form only, Numberalone i am getting
    $check =  $this->common_model->getRecords('leads',array("phone_no"=>$lead));

    if(count($check) > 0) {
        $lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead));
        if($lead->assignto_self != 0) {
            $assignto = $lead->assignto_self;
            $key = 'Self Assign';
        } else if($lead->assignto_se != 0) {
            $assignto = $lead->assignto_se;
            $key = '';
        } else if($lead->assignto_tl != 0) {
            $assignto = $lead->assignto_tl;
            $key = '';
        } else if($lead->uploaded_by != 0) {
            $assignto = $lead->uploaded_by;
            $key = 'Uploaded by';
        }

        $user = $this->common_model->getRecored_row('admin',array("id"=>$assignto));
        $role = $this->common_model->getRecored_row('role',array("id"=>$user->role));
        $this->session->set_flashdata('message', array('message' => 'This Lead Already exist with '.$user->name.' ('.$role->role.') '.' ','class' => 'danger'));

        redirect(base_url().'leads');
    } else {
    redirect(base_url().'leads/add_newlead/'.$lead);
}

这是我的数据库列

enter image description here

我也尝试过这样,无法获得输出:

$lead = $_POST['number'];
        $check1 =  $this->common_model->getRecords('leads',array("landline_no"=>$lead));
        $check =  $this->common_model->getRecords('leads',array("phone_no"=>$lead));
        echo "<pre>";
        //print_r($check1); exit;
        // $landline= $check[0]['landline_no'];  
         $landline= $check1[0]['landline_no'];
        if(count($check)||count($check1)  > 0) {
            $lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead,"landline_no"=>$landline));

在这里,我将为此提供以下答案

public function checklead() {
$lead = $_POST['number'];

if($this->common_model->getRecords('leads',array("phone_no"=>$lead)))
{
$check=$this->common_model->getRecords('leads',array("phone_no"=>$lead));
}
else
{
$check=$this->common_model->getRecords('leads',array("landline_no"=>$lead));
}
//echo "<pre>";
//echo $check; 
//print_r($check);  exit;
$p= $check[0]['phone_no'];
$l= $check[0]['landline_no']; 
// exit;
if(count($p) > 0 || count($l)>0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$p));
$lead1 = $this->common_model->getRecored_row('leads',array("landline_no"=>$l));

if($lead->assignto_self != 0 || $lead1->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0 || $lead1->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';
} else if($lead->assignto_tc != 0 || $lead1->assignto_tc != 0) {
$assignto = $lead->assignto_tc;
$key = '';
} else if($lead->assignto_sm != 0 || $lead1->assignto_s != 0) {
$assignto = $lead->assignto_sm;
$key = '';
} else if($lead->assignto_tl != 0 || $lead1->assignto_tl != 0) {
$assignto = $lead->assignto_tl;
$key = '';
} else if($lead->uploaded_by != 0 || $lead1->uploaded_by != 0) {
$assignto = $lead->uploaded_by;
$key = 'Uploaded by';
}

$user = $this->common_model->getRecored_row('admin',array("id"=>$assignto));
$role = $this->common_model->getRecored_row('role',array("id"=>$user->role));

$this->session->set_flashdata('message', array('message' => 'This Lead Already exist with '.$user->name.' ('.$role->role.') '.' ','class' => 'danger'));
redirect(base_url().'leads');
} else {
redirect(base_url().'leads/add_newlead/'.$lead);
}
}

0 个答案:

没有答案