1

我有一张这样的桌子

+-----------------------------------------------------------------+
|                              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

现在我必须为注册和登录“ali”的用户应用两个不同的删除查询,一个为只注册但没有尝试登录“hamza,sam”并且登录日期='0000-00-00'的用户应用

我正在这样if-statment使用

 $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;
    }

我很困惑,making some mistake in if-statment我猜。当我运行此代码时,它只执行else if。它也应该执行first if,因为这两种情况都根据我的数据库发生

4

1 回答 1

4

我想你想检索行数,所以:

 $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;
    }

编辑 :

<?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;
    }

?>
于 2012-05-09T21:38:02.980 回答