简体   繁体   中英

Transact-SQL and PHP issue

Running this query in the SQLManagement studio returns a result set of 162 Rows

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' ) 

which I got from echo ing the results of this code on my PHP page

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']."'");

the result set of the PHP based Query is 0 rows, and I cannot for the life of me see the issue...

here is the whole section that is supposed to build a table of the results

$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>";

You'll be needing % around $_POST['custstat'] if you want it to do a LIKE as in your first SQL statement.

You have them in the echo , but not in the actual SQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM