我从两个表中有两个查询,一个是属性,第二个是属性图像。
PropertyID字段在两个具有 PK--->FK 关系的表中都可用。
现在我的问题是如何使用我收到的propertyID的值
第一个查询并在第二个查询中使用它来检索每个属性的图像。
我已经写了一些代码,但是我收到了这个错误信息:
注意:尝试在线获取 C:\xampp\htdocs\Scale-Property\spd\index.php 中非对象的属性.......
这是我的代码:
<?php
require_once('../Admin Panel/db.php');
if(isset($_POST['Province']) && isset($_POST['District']) && isset($_POST['radio']))
{
$provincename=$_POST['Province'];
$districtname=$_POST['District'];
$propertystatus=$_POST['radio'];
$query = "SELECT
properties.PropertyID,
properties.PropertyName,
some other fields......,
Provinces.ProvinceName,
districts.DistrictName,
pds.PDName,
propertyimages.PropertyID
FROM properties, provinces, districts, pds, propertyimages
WHERE Provinces.ProvinceID=Properties.ProvinceID
AND districts.DistrictID=Properties.DistrictID
AND pds.PDID=properties.PDID
AND ProvinceName='".$provincename."'
AND DistrictName='".$districtname."'
AND PropertyDealType='".$propertystatus."'
ORDER BY properties.PropertyID";
$queryrun= $connection->query($query); // first query run in here
while ($row= $queryrun->fetch_assoc()) // in here trying to store the propretyID
{
if( $connection->error ) exit( $connection->error );
$count= $queryrun->num_rows;
echo 'You Have Got <b>'. $count .' </b>out of 326 Records';
while($row = $queryrun->fetch_assoc())
{
$imagequery ="SELECT PropertyID, ImagePath, ImageName, FROM properties WHERE PropertyID = '".$row['PropertyID']."'";
// Now i want to use the stored value of propertyID in here for retrieving the
Images of related property
}
$imagequery_run= $connection->query($imagequery);
if($imagequery_run->num_rows > 0)
{
while ($imagerow = $imagequery_run ->fetch_assoc())
{
?>
<div class="propertywrapperviewmore">
<div class="propertysingleimageviewmore">
<a href="property.php?PropertyID=<?php
echo htmlentities($imagerow['PropertyID']) ?>&PropertyID=<?php echo htmlentities($propertyrow['PropertyID']) ?>">
<img src="<?php echo htmlentities($imagerow['ImagePath']) ?>" width="227" height="147" alt="<?php echo htmlentities($imagerow['ImageName']) ?>" ></a>
</div>
<div class="propertyIDviewmorelablevalue">
<div class="propertyIDL">Property ID:</div>
<div class="propertyIDV"><?php echo $row['PropertyID']?></div>
</div>
<div class="propertyIDviewmorelablevalue">
<div class="propertyIDL">Property Name:</div>
<div class="propertyIDV"><?php echo $row['PropertyName']?></div>
</div>
</div>
<?php
}
}
}
}
?>