dtol41388 2017-05-19 04:27
浏览 65
已采纳

如何使用elesif获取不同的错误消息

I am working on one Login system which is send a verification link to the user and user have to verify within the one hour.

So When user click on verification link. I get user id and the code form url.

So by using this First i Will check is it correct or not form database. This is the query.

  $query = $this->db
        ->select('id,expiry_time')
        ->where('id', $id)
        ->where('code', $code)
        ->get('candidate');
    $data = $query->row_array();

So I have to check if user has excluded the expiry_time limit or not so i use elseif.

if ($data === null) {
      echo "Verification code not correct";
} elseif ($data['expiry_time'] < $expiry_time) {
      echo "Your verification Time is expire ";
} else {
      echo "Code is correct & Time is Not Expire yet";
}

So here i am facing a problem. I did not get the proper message.

I want Separate Message if code is not correct & if time is expire. I am little confused about it so if you suggest any correct way of getting proper error message than please tell me. Thanks.

  • 写回答

2条回答 默认 最新

  • dqo58772 2017-05-19 04:52
    关注

    Your ElesIf Loop Looks Correct. I Think You Need to Understand it first.

    so this first if the condition

    if ($data === null) {
      echo "Verification code not correct";
    }   
    

    Here I know why you use Null but you can do if with the empty() also. So if your user code is not correct then you can return this message to the view.

    if (empty($data) {
       return $code_incorrect; //Your Code incorrect message
    } 
    

    Now If code is correct but time is expire then the elseif gives you the error message regarding this.

    elseif ($data['expiry_time'] < $expiry_time) {
        return $time_expire;  // Your Time Expire message for user.
    }
    

    If code is correct and time expire you get error message of expiry and if code is incorrect then you get the error message for code incorrect.

    now then else statement

    else {
      return $sucess; //sucess message thet code is correct and time is not expire yet
     }
    

    Here you can get the success message if both the condition is true.

    This is the syntax of elseif

       if (condition) {
         code to be executed if this condition is **true**;
       } elseif (condition) {
         code to be executed if this condition is **true**;
       } else {
          code to be executed if all conditions are **false**;
       }
    

    I hope You Understand it properly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?