【问题标题】:How to compare value from table in call back function in codeigniter form validaiton如何在codeigniter表单验证的回调函数中比较表中的值
【发布时间】:2019-05-05 13:15:07
【问题描述】:

这是我在 CodeIgniter 中用于表单验证的回调函数

public function user_check($str)
{
    if ($str == 'sounitkar13')
    {
        return TRUE;
    }
    else
    {

        $this->form_validation->set_message('user_check', 'The %s is not found in our record');
        return FALSE;
    }
}

现在我正在将 $str 与“sounitkar13”进行比较,但我有一个存储了 100 个用户名的表,所以我想与这 100 个用户名进行比较,如果它与这 100 个用户名中的任何一个匹配,则返回 TRUE,否则返回 FALSE。 ( 与 is_unique 函数相反。

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    你必须使用 where 条件对表行做条件

    $query = $this->db->get_where('table', array(
                'username' => $str
            ));
    
    $count = $query->num_rows();
    
    if ($Count != 0)
        {
            return TRUE;
        }
        else
        {
    
            $this->form_validation->set_message('user_check', 'The %s is not found in our record');
            return FALSE;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 2016-10-23
      相关资源
      最近更新 更多