php 中的查询找不到正确的值
queries in php, cannot find the correct value
我有一个 "shop" 脚本,我想显示来自 sql 数据库的收入值,但我不知道我做错了什么因为我得到的两个值相同 :(
<?php
$x = date('d');
$res = $db->query("SELECT sum(amount) FROM orders WHERE SUBSTRING(date,6,2) = '$x' AND address != 'NONE' AND method='Bitcoin' OR method='PerfectMoney'");
$cols = $res->fetch_row();
echo "$".$cols[0];
?>
<?php
$mth = date('m');
$res = $db->query("SELECT sum(amount) FROM orders WHERE SUBSTRING(date,9,2) = '$mth' AND address != 'NONE' AND method='Bitcoin' OR method='PerfectMoney'");
$cols = $res->fetch_row();
echo "$".$cols[0];
?>
这是代码
问题出在哪里?
哦,这是我自己想出来的:(
SUBSTRING(date,6,2) = '$x'"); changed this one to
SUBSTRING(date,9,2) = '$x'");
和
SUBSTRING(date,9,2) = '$mth'"); and this one to
SUBSTRING(date,6,2) = '$mth'");
我有一个 "shop" 脚本,我想显示来自 sql 数据库的收入值,但我不知道我做错了什么因为我得到的两个值相同 :(
<?php
$x = date('d');
$res = $db->query("SELECT sum(amount) FROM orders WHERE SUBSTRING(date,6,2) = '$x' AND address != 'NONE' AND method='Bitcoin' OR method='PerfectMoney'");
$cols = $res->fetch_row();
echo "$".$cols[0];
?>
<?php
$mth = date('m');
$res = $db->query("SELECT sum(amount) FROM orders WHERE SUBSTRING(date,9,2) = '$mth' AND address != 'NONE' AND method='Bitcoin' OR method='PerfectMoney'");
$cols = $res->fetch_row();
echo "$".$cols[0];
?>
这是代码 问题出在哪里?
哦,这是我自己想出来的:(
SUBSTRING(date,6,2) = '$x'"); changed this one to
SUBSTRING(date,9,2) = '$x'");
和
SUBSTRING(date,9,2) = '$mth'"); and this one to
SUBSTRING(date,6,2) = '$mth'");