douxi3554
douxi3554
2012-05-09 21:24
浏览 37
已采纳

如何在不同的日期php中应用两个不同的查询

i have a table like this

+-----------------------------------------------------------------+
|                              seeker                             |
+----+-------+----------+---------------+-------------------------+
| id | name  | password | register_date | login_date | limit_date |
+----+-------+----------+---------------+------------+------------+
| 01 | ali   |   ****   |  2012-02-08   | 2012-02-09 | 2012-03-09 |
| 02 | hamza |   ****   |  2012-04-10   | 0000-00-00 | 0000-00-00 |
| 03 | sam   |   ****   |  2012-04-15   | 0000-00-00 | 0000-00-00 |
+----+-------+----------+---------------+------------+------------+

register_date = when user ger registered
login-date= when user attempt to login
limit date= login-date + 1 month

now i have to apply two different delete query one for user who register and login "ali" one for user who only register but didnot attempt to login "hamza, sam" and have login-date='0000-00-00'

i am using if-statment like this

 $qry="select * from seeker where login_date='0000-00-00'";
    $rs= mysql_query($qry, $con);
    $res=mysql_fetch_array($rs);

    if($res==0)
    {
      //query to delete user who has login date
      $q= "delete from seeker where current_date = limit_date'";
      if($rq=mysql_query($q, $con));
      echo "$q";

    }

   else if($res!=0)
    {
        //query to delete user who didnot login and has login-date='0000-00-00'
        $qry1="delete from seeker where '$days' >= 30";
            $rs1= mysql_query($qry1, $con);
            echo $qry1;
    }

i am very confused and making some mistake in if-statment i guess. when i run this code it executes only else if . it should also execute first if because both conditions occurs according to my database

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpt8910
    dpt8910 2012-05-09 21:38
    已采纳

    i guess u wanted to retrieve the number of rows so :

     $qry="select * from seeker where login_date='0000-00-00'";
        $rs= mysql_query($qry, $con);
        $res=mysql_num_rows($rs);
    
        if($res==0)
        {
          //query to delete user who has login date
          $q= "delete from seeker where current_date = limit_date'";
          if($rq=mysql_query($q, $con));
          echo "$q";
    
        }
    
       else if($res!=0)
        {
            //query to delete user who didnot login and has login-date='0000-00-00'
            $qry1="delete from seeker where '$days' >= 30";
                $rs1= mysql_query($qry1, $con);
                echo $qry1;
        }
    

    EDIT :

    <?php
    
        $qry="select * from seeker where login_date='0000-00-00'";
        $rs= mysql_query($qry, $con);
        $res=mysql_num_rows($rs);
    
    
        if($res!=0)
        {
            $qry1="delete from seeker where '$days' >= 30";
                $rs1= mysql_query($qry1, $con);
                echo $qry1;
        }
    
        $qry="select * from seeker where current_date = limit_date";
        $rs= mysql_query($qry, $con);
        $res=mysql_num_rows($rs);
    
        if($res!=0)
        {
             $q= "delete from seeker where current_date = limit_date";
                $rs1= mysql_query($qry1, $con);
                echo $qry1;
        }
    
    ?>
    
    点赞 评论

相关推荐