下面是用于查询一个人的总票证的查询。 fWork是该人的ID。将变量放入条件中的最佳方法是什么?
我应该声明类似$ID = $_GET['ID'];
的东西,然后变成fWork = $ID
或fWork = ?
,然后将$_GET[ID]
放入这样的参数array($_GET['ID'])
$open_count = " SELECT * FROM TicketO WHERE Assigned = 0 AND fWork = 983";
$query = sqlsrv_query($NEI,$open_count, array(), array( "Scrollable" => 'buffered' ));
$open_tickets_count = sqlsrv_num_rows($query);
echo " open tickets: " . $open_tickets_count;
此外,我在查询中包含UNION ALL时遇到麻烦,我是否缺少一些括号?它返回false。
$total_count = "SELECT * FROM TicketO WHERE fWork = '983'
UNION ALL
SELECT * FROM TicketD WHERE fWork = '983'";
答案 0 :(得分:-1)
首先,我建议您验证ID是否包含在请求中
$fWork = '';
if(isset($_GET['ID']))
$fWork = $_GET['ID'];
$total_count = "SELECT * FROM TicketO as O WHERE O.fWork = '".$fWork."'
UNION ALL
SELECT * FROM TicketD as D WHERE D.fWork = '".$fWork."'";
我无法告诉您UNION ALL为什么不起作用,我需要查看该表的结构,但是要记住,在UNION ALL中您必须返回相同数量的列,并且这些列必须具有相同的数据输入