dtol41388 2013-02-01 10:44
浏览 55

PHP - mysql_query返回0行

I am running a query in php using mysql_query() function, but it is returning zero rows, whereas when I run same query in phpMyAdmin I am getting one row. Don't know what is making things wrong. I have made a same table structure on sqlfiddle with the query

SELECT * FROM cart_discount WHERE email_counter < 1 AND cart_time BETWEEN '2013-01-31 00:00:00' AND '2013-02-01 23:59:59'

http://sqlfiddle.com/#!2/cceb7/4

Please guide where php is making trouble..

This is how query is generated and executed.

$date1 = date('Y-m-d 00:00:00', strtotime(' -1 day')); 
$date2 = date("Y-m-d 23:59:59");

$query = "SELECT *
            FROM cart_discount
            WHERE email_counter < 1
            AND cart_time >= '$date1'
            AND cart_time <= '$date2'";

$ssql = mysql_query($query, $con) or die('Problem running query: ' . mysql_error());

if (mysql_num_rows($ssql) > 0) {
//do something
} else {
echo 'No rows found';
}
  • 写回答

2条回答 默认 最新

  • douzhong2954 2013-02-01 11:00
    关注

    Try to print these variable first $date1 & $date2 before executing it using mysql_query. see what it is printing if there is some format mismatch with the database then change it. perhaps this might be the only reason. Apart from this Suggestion: There are lots of things you can do to debug your problem. print the actual query what you are executing. copy it and execute it in phpmyadmin.compare the differences.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥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 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看