du9537 2014-05-26 03:06
浏览 8

按日期排序返回空查询

I'm attempting to group information in a SQL Database (Using MYSQL) through a php script. Here's my function that I wrote. (Today is my first day with php, technically second)

function getQuery($ResultType, $tbl_name, $Date) {
    if($ResultType == 'Day') { return "SELECT * FROM $tbl_name where Date($tbl_name.Date) = DATE('$Date')"; }
    if($ResultType == 'Year') { return "SELECT * FROM $tbl_name where Year($tbl_name.Date) = Year('$Date')" ; }     
    if($ResultType == 'Month') { return "SELECT * FROM $tbl_name where Year($tbl_name.Date) = Year('$Date') and Month($tbl_name.Date) = Month($Date)"; }
}

When trying to get the data by "Day" or "Year" it works, but the query that is trying to select everything for that month is returning 0 rows.

Date is formatted as yyyy-mm-dd if it matters.

  • 写回答

1条回答 默认 最新

  • dongxiequ3724 2014-05-26 03:14
    关注

    There is a missing quote in the last query. Change

     Month($Date)
    

    to

     Month('$Date')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?