在SQLManagement工作室中运行此查询将返回162行
的结果集SELECT order_num,
status,
ship_date,
cust_ord_num,
weight,
carrier_desc,
consignee,
cases
FROM v1oemf
WHERE ACCOUNT = 'NESTLE'
AND status LIKE '%Shipped%'
AND ( ship_date BETWEEN '20120327' AND '20120403' )
我从我的PHP页面echo
获得此代码的结果
echo "SELECT Order_num,Status,Ship_date,Cust_ord_num,Weight,Carrier_desc,Consignee,Cases FROM V1OEMF WHERE Account = '" . $_POST['account'] . "' AND Status LIKE '%". $_POST['custstat'] ."%' AND (Ship_date BETWEEN '".$_POST['start_date']."' AND '".$_POST['end_date']."')";
$rs=odbc_exec($link,"SELECT Order_num,Status,Ship_date,Cust_ord_num,Weight,Carrier_desc,Consignee,Cases FROM V1OEMF WHERE Account = '" . $_POST['account'] . "' AND Status LIKE '". $_POST['custstat'] ."' AND Ship_date BETWEEN '".$_POST['start_date']."' AND '".$_POST['end_date']."'");
基于PHP的查询的结果集是0行,我不能为我的生活看到问题......
这是应该构建结果表的整个部分
$rs=odbc_exec($link,"SELECT Order_num,Status,Ship_date,Cust_ord_num,Weight,Carrier_desc,Consignee,Cases FROM V1OEMF WHERE Account = '" . $_POST['account'] . "' AND Status LIKE '". $_POST['custstat'] ."' AND Ship_date BETWEEN '".$_POST['start_date']."' AND '".$_POST['end_date']."'");
$num = odbc_num_rows($rs);
echo $num;
echo "<table>";
echo "<thead><tr class='header'>";
echo "<td>Order #</td><td>Status</td><td>Ship Date</td><td>Sales Order #</td><td>Consignee</td><td>Carrier</td><td>Cases</td><td>Weight</td>";
echo "</tr></thead>";
while (odbc_fetch_row($rs)) {
echo "<tr><td id='f1'><a class='ow' href='' id='" . odbc_result($rs,'Order_num') . "'>" . odbc_result($rs,'Order_num') . "</a></td><td id='f2'>" . odbc_result($rs,'Status') . "</td><td id='f3'>" . odbc_result($rs,'Ship_date') . "</td><td id='f5'>" . odbc_result($rs,'Cust_ord_num') . "</td><td id='f6'>" . odbc_result($rs,'Consignee') . "</td><td id='f7'>" . odbc_result($rs,'Carrier_desc') . "</td><td id='f8' align='right'>" . odbc_result($rs,'Cases') . "</td><td id='f9' align='right'>" . odbc_result($rs,'Weight') . "</td></tr>";
}
echo "</table>";
答案 0 :(得分:4)
如果您希望%
像第一个SQL语句那样执行$_POST['custstat']
,那么LIKE
周围需要echo
。
您在{{1}}中拥有它们,但在实际的SQL中却没有。