dqnk57224
2014-10-27 21:02
浏览 42
已采纳

如何获取当前日期的数据仅显示

enter image description hereI have this, but not sure how to get current date to show only. I also know that this needs to be fixed so it does not get SQL injection. Anyone have an idea what I can do to show the current date only of the records.

$sql = "SELECT id, lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt FROM requests WHERE status='Completed' AND compUser='xgrh'CURDATE()";
$results = mysql_query($sql) or die(mysql_error());

This is on my admin page

<tr>
        <td style="width: 125px"><a href="xgrhCompleted.php" target="Frame">xgrh</a></td>
        <td style="width: 125px" align="center"><a href="xgrhCompleted.php" target="Frame"><?php $result = mysql_query("SELECT COUNT(*) FROM requests WHERE status='Completed' AND compUser='xgrh'");  
while($row=mysql_fetch_array($result))  
{  
echo $row['COUNT(*)'];  
} ?></a></td>
    </tr>

</div>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dqr6434 2014-10-27 21:12
    已采纳

    I'd do it like this:

    Set variable before query with entire string

    $user = 'xgrh'.Date('m/d/y');
    

    Query:

    $sql = "SELECT id, lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt FROM requests WHERE status='Completed' AND compUser='$user'";
    

    you need to make sure what the exact used dateformat your date column is (days with leading zero or without, month with leading zero or without) and set the variables dateformat according.

    If the query should be like in your last comment:

    $date = Date('m/d/y');
    
        $sql = "SELECT id, lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt FROM requsts WHERE status='Completed' AND compUser='xgrh' AND compDT = '$date'";
    

    This:

        <tr>
            <td style="width: 125px"><a href="xgrhCompleted.php" target="Frame">xgrh</a></td>
            <td style="width: 125px" align="center"><a href="xgrhCompleted.php" target="Frame"><?php $result = mysql_query("SELECT COUNT(*) FROM requests WHERE status='Completed' AND compUser='xgrh'");  
    while($row=mysql_fetch_array($result))  
    {  
    echo $row['COUNT(*)'];  
    } ?></a></td>
        </tr>
    

    is completely wrong. You want to

    a) run a query
    b) echo the result
    

    You're totaly mixing stuff

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题