解决方案 »

  1.   

    先不说你的逻辑,光语法上就有错误
    $sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate";
    这行之前都没变量$signin_time,没报错?还是你屏蔽了?另外,能不交给SQL来运算的,就别让SQL来运算。你直接读取最后一次签到时间,然后再跟现在的时间对比,大于一定的时间就去更新签到数据,然后输出成功信息,否则就给出失败的提示。
      

  2.   


    $signin_time 是我从sql中读出来的 最近签到时间  我这么执行 主要就是想用那个很方便的diffdate函数,因为可以返回相差多少天,我就很容易知道签到情况,请问这样为什么从不执行SQL语句,就是执行结果即便显示我断签但是今天签到了,数据库里的数据也没有改变(包括连续天数和最近签到时间)
      

  3.   

    1、你使用 odbc_connect 连接数据库, 怎么又使用 mysql_query 操作数据库?
    2、$sql_date_diff="select datediff('$new_signin_time','$signin_time') as diffdate"; 中
      $new_signin_time,$signin_time 未赋值
      

  4.   

       您好!我已经把odbc连接改为mysql连接了,$new_signin_time我去的是当前系统时间并且进行了日期格式的格式化
    $new_signin_time=date("y-m-d h:i:s",time());signin_time是数据表俩原有的属性,所以$去掉了,直接用数据库表里面的值,现在这句话是这样写的
    $result=mysql_query("select datediff('$new_signin_time',signin_time) as diffdate where stu_id=$stu_id");
     $diffdate=mysql_fetch_array($result);
    但是diffdate的返回值还是有问题,接下来的代码是这样的
    if($diffdate==0){//不可重复签到
            header("Location:http://localhost:801/SignIn/noRepeat.html");
           }else if($diffdate==1){//连续签到
            mysql_query("update signin set con_days=con_days+1,signin_time=$new_signin_time 
         where stu_id=$stu_id");
            header("Location:http://localhost:801/SignIn/con_signinSuccess.php");
           }else if($diffdate>1){//断签但今日签到
            mysql_query("update signin set con_days=1,signin_time=$new_signin_time 
         where stu_id=$stu_id");
            header("Location:http://localhost:801/SignIn/signinSuccess.html");
           }
           
         mysql_close($con);
      

  5.   

    $diffdate=mysql_fetch_array($result); 后
    $diffdate 是数组
    你至少需要 $diffdate = $diffdate[0];
      

  6.   

    我按您说的,但是结果和之前一样,我现在的问题是我返回的结果总是不可重复签到,也就是说$diffdate[0]总是0,但是数据库里的数据不是这样的。。
    这是现在的代码:
    <?php  
         $con = mysql_connect("localhost","root","lzw0201");
         if (!$con){
         die('Could not connect: ' . mysql_error());
         }
         mysql_select_db("test",$con);
        
    $stu_id="12570219";//实际中由登陆表单获取; 
    $new_signin_time=date("y-m-d h:i:s");

         $result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id");
         $diffdate=mysql_fetch_array($result);
           if($diffdate[0]==0){//不可重复签到
            header("Location:http://localhost:801/SignIn/noRepeat.html");
           }else if($diffdate[0]==1){//连续签到
            mysql_query("update signin set con_days=con_days+1,signin_time=$new_signin_time 
         where stu_id=$stu_id");
            header("Location:http://localhost:801/SignIn/con_signinSuccess.php");
           }else if($diffdate[0]>1){//断签但今日签到
            mysql_query("update signin set con_days=1,signin_time=$new_signin_time 
         where stu_id=$stu_id");
            header("Location:http://localhost:801/SignIn/signinSuccess.html");
           }
           
         mysql_close($con);
    ?>
      

  7.   

    $result=mysql_query("select datediff($new_signin_time,signin_time) as diffdate where stu_id=$stu_id");
    怎么没有 from
      

  8.   

    因为不在数据表里面。。我也发现娶不到结果了。。我的表里面只有那三项。。好吧  我以为想计算的话就要用select形式,我从网上找到的请问我从外面穿进去一个只和表里面的一个值进行datediff运算,返回datediff这个差值 应该怎么写
      

  9.   

    因为不在数据表里面。。我也发现娶不到结果了。。我的表里面只有那三项。。好吧  我以为想计算的话就要用select形式,我从网上找到的请问我从外面穿进去一个只和表里面的一个值进行datediff运算,返回datediff这个差值 应该怎么写我调好了  谢谢您的帮助  居然烦了这么弱智的问题  
      

  10.   

    现在可以判断正确了,但是
    else if($diffdate[0]>1){//断签但今日签到
            mysql_query("update signin set con_days=1,signin_time=$new_signin_time 
         where stu_id=$stu_id");
            header("Location:http://localhost:801/SignIn/signinSuccess.html");
           }
    条件句里面的mysql_query语句却没被执行 ,为什么呢
      

  11.   

    mysql_query("update signin set con_days=1,signin_time='$new_signin_time' 
          where stu_id=$stu_id");