我正在使用 PHP 和 MySql。以下是我的代码:
$con=mysql_connect("localhost","XYZ","pqr") or die("Failed to connect with database!!!!");
mysql_select_db("LMN", $con);
$sql =" SELECT DATE_FORMAT( FROM_UNIXTIME( transaction_date ) , '%d/%m/%Y') 'date', COUNT(*) 'total count', SUM(transaction_status = 'success') ";
$sql .=" success, SUM(transaction_status = 'inprocess') inprocess, SUM(transaction_status = 'fail') fail, ";
$sql .=" SUM(transaction_status = 'cancelled') cancelled FROM user_transaction WHERE ";
$sql .=" transaction_date >= 1325376000 AND transaction_date <= 1373846400 GROUP BY date(FROM_UNIXTIME(transaction_date)) ";
$r= mysql_query($sql) or die(mysql_error());
$result = mysql_fetch_array($r, MYSQL_ASSOC);
print_r($result);
die;
如果我在 PHPMyadmin 中运行上述查询,它会给我完美的结果(即 47 条匹配记录),但是当我运行 PHP 文件时,它只给我一条记录如下:
Array
(
[date] => 11/04/2012
[total count] => 1
[success] => 0
[inprocess] => 0
[fail] => 0
[cancelled] => 1
)
实际上这是第一个匹配的记录。你能帮我在 PHPMyadmin 中获得所有匹配的记录数组吗?提前致谢。