0
我正在檢查值是否唯一。我有這個功能,但是如何再次檢查。Codeigniter - 檢查值是否唯一
這是函數(它的工作):
public function is_unique($field, $val)
{
$this->db->select($field)->where($field, $val);
$result = $this->get();
$result = $result['data'];
return $bool = count($result) == 0 ? $val : FALSE;
}
這是我檢查的價值,看它是否是獨一無二的:
$unique_code = random_string('alnum', 6);
$unique_code = $this->posts->is_unuque('unique_code', $unique_code) != FALSE ? $unique_code: random_string('alnum', 6);
如何創建IF函數新價值返回FALSE並檢查新值(使循環直到值是唯一的)?