我有这个查询,但它没有显示任何数据,我得到空白结果:
SELECT * FROM oc_product p
LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id)
WHERE pd.language_id = '1'
GROUP BY p.product_id
ORDER BY pd.name ASC
我认为问题出在oc_product_description
表中(字段描述)。
我也尝试 SELECT * FROM oc_product
这工作正常,但这SELECT * FROM oc_product_description
不工作,SELECT name FROM oc_product_description
这工作正常......
这是我的完整代码
<?php
// DB
define('DB_DRIVER', 'mysqli');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'opencart');
define('DB_PORT', '3306');
define('DB_PREFIX', 'oc_');
$db = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
if (mysqli_connect_errno()) {
echo 'Database connection failed with following errors: ' . mysqli_connect_error();
die();
}
$products = [];
//$sql = $db->query("SELECT * FROM ". DB_PREFIX ."product p LEFT JOIN " . DB_PREFIX . "product_description pd ON pd.product_id = p.product_id WHERE pd.language_id = 1");
$sql = $db->query("SELECT * FROM oc_product p LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '1' GROUP BY p.product_id ORDER BY pd.name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$products[] = $row;
}
echo json_encode($products);
?>
请任何人帮助我...谢谢