I've spent the past couple hours combing this site and the web for a solution to my problem. I'm certain it is an issue of syntax, and that it's a simple fix. When running the following query in phpmyadmin, I get the desired results. I'm joining two tables and displaying sums from each. I used phpmyadmin to generate php code but return 0 lines. Changing the SELECT query in php to a simple line which gathers only the sum and records from one table outputs multiple rows. It is only when I use the multiple SELECTS from the more advanced query that I get no results.
SELECT
od.orderID,
od.owed,
od.freight,
op.paid
FROM
(
SELECT
acct,
orderID,
SUM(price * qty) AS owed,
freight
FROM
old_details
GROUP BY
orderID
) AS od
INNER JOIN (
SELECT
orderID,
SUM(payment) AS paid
FROM
old_payment
GROUP BY
orderID
) AS op ON (op.orderID = od.orderID)
WHERE od.acct='AS3576E'
The PHP script is...
<?php
include_once "connect.php";
$cID = 'AS3576E';
$query = "SELECT od.orderID, od.owed, od.freight, op.paid
FROM ( SELECT acct, orderID, SUM(price * qty) AS owed, freight
FROM old_details
GROUP BY orderID ) AS od
INNER JOIN (
SELECT orderID, SUM(payment) AS paid
FROM old_payment
GROUP BY orderID ) AS op ON (op.orderID = od.orderID)
WHERE od.acct='$cID'";
$line=0;
$results = mysqli_multi_query($link, $query);
while($row=mysqli_fetch_array($results)){
echo "oid$line=$row[orderID]&";
echo "odate$line=$row[invDate]&";
echo "oowed$line=$row[owed]&";
echo "opaid$line=$row[paid]&";
echo "ofreight$line=$row[freight]&";
$line++;
}
echo "line=$line";
mysqli_close($link);
?>
I have tried mysqli_multi_query and mysqli_query. I have tried many different tweaks. There isn't a problem connecting to the database, as a change in the php query outputs rows of data. Any help would be greatly appreciated.