大家好我已经玩了几分钟的Oracle SQL和PHP所以请原谅我,如果这听起来很新秀。 我在我的PHP代码中得到了这个查询,将4个表连接在一起,这是查询:
SELECT P.PTY_ID,
P.PTY_UNITNUM,
P.PTY_STREET,
P.PTY_POSTCODE,
P.PTY_SUBURB,
P.PTY_CITY,
T.P_TYPE_NAME,
L.LIST_PRICE,
L.SALE_PRICE,
C.SELLER_FNAME,
C.SELLER_LNAME,
L.AVAILABILITY
FROM PROPERTY_TYPE T,
PROPERTY P,
CUSTOMER C,
LISTINGS L
WHERE P.P_TYPE_ID = T.P_TYPE_ID(+)
AND L.SELLER_ID = C.SELLER_ID(+)
AND L.PTY_ID = P.PTY_ID(+)
ORDER BY P.PTY_ID;
简而言之,我想要实现的是在一个表格中一起显示房产详细信息,房源信息(价格,可用性)和客户名称。该查询在SQL开发人员中完美运行并给了我想要的结果,但它在我的PHP文件中不起作用并且没有给我任何结果但是空白。
为了调试,我使用了另一组数据并放入,它也运行良好。因此我可以告诉PHP代码很酷并返回查询。但我找不到任何问题。谁能帮我?我错误地使用了连接语句吗?
我只是在下面添加我的PHP代码,以防您感兴趣:
<!DOCTYPE html>
<html>
<head><title>Update/Delete Property</title></head>
<body>
<center><h2>Property Records</h2></center>
<?php
$conn = oci_connect("username","password","database");
$query = "SELECT P.PTY_ID, P.PTY_UNITNUM, P.PTY_STREET, P.PTY_POSTCODE, P.PTY_SUBURB, P.PTY_CITY, T.P_TYPE_NAME,
L.LIST_PRICE, L.SALE_PRICE,
U.SELLER_FNAME, U.SELLER_LNAME,
L.AVAILABILITY
FROM PROPERTY_TYPE T, PROPERTY P, CUSTOMER C, LISTINGS L
WHERE P.P_TYPE_ID = T.P_TYPE_ID(+)
AND L.SELLER_ID = U.SELLER_ID(+)
AND L.PTY_ID = P.PTY_ID(+)
ORDER BY P.PTY_ID";
$stmt = oci_parse($conn,$query);
oci_execute($stmt);
?>
<table border="2" align="center">
<tr>
<th><b>Property ID</th>
<th><b>Unit Number</th>
<th><b>Street</th>
<th><b>Postcode</th>
<th><b>Suburb</th>
<th><b>City</th>
<th><b>Property Type</th>
<th><b>Listing Price</th>
<th><b>Sale Price</th>
<th colspan = '2'><b>Seller Name</th>
<th><b>Availability</th>
<th><b>Checkbox</th>
</tr>
<?php
while ($row = oci_fetch_array($stmt))
{
?>
<tr>
<td><?php echo oci_result($stmt,"PTY_ID");?></td>
<td><?php echo oci_result($stmt,"PTY_UNITNUM");?></td>
<td><?php echo oci_result($stmt,"PTY_STREET");?></td>
<td><?php echo oci_result($stmt,"PTY_POSTCODE");?></td>
<td><?php echo oci_result($stmt,"PTY_SUBURB");?></td>
<td><?php echo oci_result($stmt,"PTY_CITY");?></td>
<td><?php echo oci_result($stmt,"P_TYPE_NAME");?></td>
<td><?php echo oci_result($stmt,"LIST_PRICE");?></td>
<td><?php echo oci_result($stmt,"SALE_PRICE");?></td>
<td><?php echo oci_result($stmt,"SELLER_FNAME");?></td>
<td><?php echo oci_result($stmt,"SELLER_LNAME");?></td>
<td><?php echo oci_result($stmt,"AVAILABILITY");?></td>
</tr>
<?php
}
oci_free_statement($stmt);
oci_close($conn);
?>
</table>
</body>
</html>
所以我尝试更改代码的一行:
AND P.PTY_ID = L.PTY_ID(+)
我开始得到一些东西......但仍然不是我想要的东西: New result
我很确定它现在是关于查询的,它是关于实体之间的连接的东西。再次,我在这里发送我的ERD,这可能会有所帮助(专注于表格列表,卖方(现在称为CUSTOMER )和PROPERTY): ERD of the entities