donglun7151 2013-12-20 15:27
浏览 90
已采纳

php mysql比较相等的日期

I am using php to access fields from 2 tables.

This part works just fine

   $sql=mysql_query('SELECT * FROM user_weeks WHERE user_id = '.$_SESSION["user_id"].' ORDER BY date DESC') or die(mysql_error());

I get the date just fine by doing this

    $infodate=$info["date"];
    echo $infodate;

However I'm trying to take that date and compare it to one in a different table as such

$sql2=mysql_query('SELECT * FROM weekly_ROI WHERE date = '.$infodate.' ') or die(mysql_error());

however, that gives me no results. I'm a noob so sorry if this code is so "2000 and late"

  • 写回答

3条回答 默认 最新

  • doutou7549 2013-12-20 15:37
    关注

    Presumably you're using a standard yyyy-mm-dd type date string in your query, which means you're lacking quotes around the date value:

    $sql2=mysql_query('SELECT * FROM weekly_ROI WHERE date = '.$infodate.' ')
                                                             ^--here          ^-- here
    

    Your query will look like

    ... WHERE date = 2013-12-18
    

    and be evaluated as a simple mathematical subtraction:

    ... WHERE date = 1983
    

    You need quotes:

    .... date = "' . $infodate . '"');
                ^--               ^--
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度