我有一个恼人的问题,我有一个使用内部联接的查询,如果我说例如SELECT *,查询打印出结果,但是当我开始插入实际的列名时它返回我失败的查询错误, " 0结果"。
我得到了这个错误
注意:尝试获取非对象的属性。
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);
......
我不想选择*,因为我将从4/5表中选择数据。
我尝试了fetch_assoc和fetch_row而不是fetch_array,我收到了相同的错误消息。
有人能指出可能导致此问题的原因吗?
表架构
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