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条回答 默认 最新

  • 普通网友 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题