I have a annoying issue, I have a query that uses inner joins, the query prints out the results if i say for example SELECT *, but the moment i start to insert the actual column names it returns my failed query error, of " 0 results".
And i get this error
Notice: Trying to get property of non-object .
SELECT COLUMN NAMES
$ord_dets = "
SELECT cod.Fname
, cod.Lname
, od.City_name
, od.Product_Name
FROM Customer_order_details cod
JOIN ord_dets od
ON od.Order_ID = cod.Order_ID
JOIN Payment p
ON p.Order_ID = cod.Order_ID
WHERE cod.Order_Id = '$OrdID';
";
$ord_result = $dbc->query($ord_dets);
if ($ord_result->num_rows > 0) {
while ($row_dets = $ord_result->fetch_array()) {
$Cust_Fname = $row_dets['Fname'];
}
} else {
echo "0 results";
}
$dbc->close();
SELECT *
$ord_dets = "
SELECT *
FROM Customer_order_details cod
JOIN ord_dets od
ON od.Order_ID = cod.Order_ID
JOIN Payment p
ON p.Order_ID = cod.Order_ID
WHERE cod.Order_Id = '$OrdID';
";
$ord_result = $dbc->query($ord_dets);
......
I do not want to select * as i will be selecting data from maybe 4/5 tables.
I have tried fetch_assoc and fetch_row instead of fetch_array and i am getting the same error message.
Can anyone point out what may be causing this issue?
Table schema
ord_dets
CREATE TABLE `ord_dets` (
`ord_dets_id` bigint(255) NOT NULL AUTO_INCREMENT,
`Order_ID` bigint(255) NOT NULL,
`custmer_ip` varchar(100) NOT NULL,
`Resturant_ID` bigint(255) NOT NULL,
`Resturant_name` varchar(100) NOT NULL,
`City_name` varchar(100) NOT NULL,
`Product_Id` bigint(255) NOT NULL,
`Product_Name` varchar(100) NOT NULL,
`Product_Price` decimal(4,2) NOT NULL,
`Date_Time_Placed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ord_dets_id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8
Customer_order_details
CREATE TABLE `Customer_order_details` (
`Order_ID` bigint(255) NOT NULL AUTO_INCREMENT,
`Customer_ID` bigint(255) DEFAULT NULL,
`Fname` varchar(100) NOT NULL,
`Lname` varchar(100) NOT NULL,
`Cust_Email` varchar(320) NOT NULL,
`Cust_M_Phone` varchar(12) NOT NULL,
`Cust_H_Phone` varchar(16) NOT NULL,
`Door_num` varchar(100) NOT NULL,
`Line_1` varchar(200) NOT NULL,
`Line_2` text NOT NULL,
`City_Name` text NOT NULL,
`Postcode` varchar(8) NOT NULL,
`Status` tinyint(4) NOT NULL,
PRIMARY KEY (`Order_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=147 DEFAULT CHARSET=outfit