Hello I have a query with while loop which is used for retrieving data but in here my query
along my while loop is in top of page so its repeating other elements specifically my
header.
Here is the code:
<?php
require_once('../Admin Panel/db.php');
if(!empty($_POST['Province']) && !empty($_POST['District']) && !empty($_POST['radio']))
{
$provincename=$_POST['Province'];
$districtname=$_POST['District'];
$propertystatus=$_POST['radio'];
$query = "SELECT
properties.PropertyID,
properties.PropertyType,
properties.PropertyDealType,
properties.PropertyRegion,
properties.PropostedPrice,
properties.DealStatus,
properties.CurrencyType,
propertyimages.ImageID,
propertyimages.ImagePath,
propertyimages.ImageName,
provinces.ProvinceName,
districts.DistrictName,
pds.PDName
FROM properties, provinces, districts, pds, propertyimages
WHERE provinces.ProvinceID=properties.ProvinceID
AND districts.DistrictID=properties.DistrictID
AND pds.PDID=properties.PDID
AND properties.ImageID=propertyimages.ImageID
AND properties.Status= 'Active'
AND properties.propertyStatus = 'APPROVED'
AND ProvinceName='".$provincename."'
AND DistrictName='".$districtname."'
AND PropertyDealType='".$propertystatus."'
GROUP BY properties.PropertyID";
$queryrun= $connection->query($query); // The query run in here
if( $connection->error ) exit( $connection->error ); // In here checks for the errors which may occure in our query
while ($row= $queryrun->fetch_assoc()) // storing the value of the query into the variable of row
{
$count= $queryrun->num_rows; // Taking the number of queries returened by the result
?>
<!DOCTYPE html>
<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="favico.ico">
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content=" spdealers Onlince Dealing," />
<meta name="Keywords" content="spdealers.com - spdealers, Property spdealers, Property spdealers, real estate Afghanistan, Afghanistan property, Afghanistan properties, property in Afghanistan, property Afghanistan, Afghanistan real estate, apartments, properties for sale Afghanistan, office space, property, buy property, sell property, rent property, commercial real estate Afghanistan, Afghanistan properties, Afghanistan properties on sale, Afghanistan property portals, Afghanistan residential real estate, rental property, flats, apartments, studio apartments, property site,makaan, makan, spdealers.com, real estate properties, Afghanistan real estate, real estate Afghanistan, property Afghanistan, Afghanistan property portal, buy property, sell property, rent property online, flats, apartments, studio apartment, rental property, commercial real estate, search property, list property, post requirement, featured builders, dealers, property index, properties in Afghanistan, property by localityProperty, Properties, Property For Sale, Find a Property, Properties for sale, Real Estate, Buy real estate. R">
<Meta name="description" content="spdealers Online Property Dealing In Afghansitan, Property Search, buy, sell, rent, lease residential, commercial propertys only on spdealers.com.">
<title>SPDealers</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="logo">
<img src="images/logo.png" alt="" />
</div>
<ul>
<li class="selected"><span>PROPERTY</span></li>
<li>View Option</li>
<li><span>HOME</span></li>
</ul>
</div>
<div id="body">
<div class="header">
<div>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
<div>
<p>Do you want to earn money and have a good income? Do you want to receive money without working hours and putting pressure over your Mind, So Please contact with us and make yourself one of our valuable Remote Employee Click Here for more information.</p>
</div>
<div id="threeimages">
<img src="images/flags.png">
<img src="images/graph.png">
</div>
</div>
</div>
<br>
<div class="footer">
<div class="featured">
<div class="propertywrapperviewmore">
<div class="propertysingleimageviewmore">
<a href="property.php?ImageID=<?php echo $row['ImageID'] ?>">
<img src="../Admin Panel/Property_Insertion_Files/<?php echo $row['ImagePath'] ?>" width="227" height="147" alt="<?php echo $row['ImageName'] ?>" style="border-radius:8px;" ></a>
</div>
<div class="propertyIDviewmorelablevalue">
<div class="propertyIDL">Property ID:</div>
<div class="propertyIDV"><?php echo $row['PropertyID']?></div>
<div align="right" style="
width:310px;
height:15px;
font-size:20px;
float:right;
padding-bottom:5px;
background-color:#000;
color:#FFF;
"><marquee behavior="scroll" scrollamount="2" onMouseover="this.scrollAmount=1" onMouseout="this.scrollAmount=6"><?php echo $row['PropertyDealType'] ?></marquee></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Property Type:</div>
<div class="propertyothersV"><?php echo $row['PropertyType']?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Address:</div>
<div class="propertyothersV"><?php echo $row['PropertyRegion'].' / Nahya: '.$row['PDName'].' / District: '.$row['DistrictName'].' / '.$row['ProvinceName']?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Total Price:</div>
<div class="propertyothersV"><?php $price = (isset($row['PropostedPrice']) && $row['PropostedPrice']!='')?
number_format($row['PropostedPrice'], 2, '.', ','):'';
echo $row['CurrencyType'].' '.$price?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Deal Status:</div>
<div class="propertyothersV"><?php echo $row['DealStatus']?></div>
</div>
<br><br><br><br>
<div class="propertysviewmoreDescription">
<div class="propertysviewmoreDescriptionL">Description:</div>
<div class="propertysviewmoreDescriptionV">
To find out more this property, please click on the VIEW MORE button. You can contact us more specific information
on this property.
<label style="float:right;"><br>View More</label>
<div>
</div>
</div>
</div>
</div>
<?php
}
if($queryrun->num_rows == 0)
{
echo "<div style='margin-left:116px; line-height: 36px;'>".'Sorry there is no Record for Your search: '." ". "<br>
Province: <b>".$provincename."</b> <br>District: <b>". $districtname."</b>
<br> Property Status: <b>".$propertystatus."</b>
<br> to search other provinces and cities
<br>
<a href='../index.php' style='text-decoration:none; font-size: 16px; color:#2a4f5e;'>Click Here</a>
</div>";
}
}
else
{
echo '<br><br>You Havent Selected The Following Properly:<br><br>
<strong>(Province)</strong> <br>
<strong>(District)</strong> <br>
<strong>(Property Status)</strong>.<br><br>';
echo "Please <a href='../index.php' style='text-decoration:none; font-size: 16px; color:#2a4f5e;'>Click Here</a> to go back";
}
?>
</div>
<div id="ads" style="margin-left:844px;">
<div id="adsone"></div>
<div id="adsthree"></div>
</div>
</div>
</div>
<div id="footer">
<div id="bottomoptions">Home About Us Advertise With Us Terms&Condition Help&Support Privacy Policy FAQ Contact Us Report A Problem
<div id="copyright"><p>All rights Reserved©2014 spdealers.com</p>
</div>
</div>
</div>
</div>
</body>
</html>
I am only guessing where your loop is supposed to be and where your breaks should be on if else conditions. They should hopefully be close...??
<?php
require_once('../Admin Panel/db.php');
class ProvinceProp
{
protected $connection;
public function __construct($connection)
{
$this->connection = $connection;
}
public $provincename;
public $districtname;
public $propertystatus;
public $num_rows;
public function ProcessPost()
{
if(!empty($_POST['Province']) && !empty($_POST['District']) && !empty($_POST['radio'])) {
$this->provincename = $_POST['Province'];
$this->districtname = $_POST['District'];
$this->propertystatus = $_POST['radio'];
$query = "SELECT
properties.PropertyID,
properties.PropertyType,
properties.PropertyDealType,
properties.PropertyRegion,
properties.PropostedPrice,
properties.DealStatus,
properties.CurrencyType,
propertyimages.ImageID,
propertyimages.ImagePath,
propertyimages.ImageName,
provinces.ProvinceName,
districts.DistrictName,
pds.PDName
FROM properties, provinces, districts, pds, propertyimages
WHERE provinces.ProvinceID=properties.ProvinceID
AND districts.DistrictID=properties.DistrictID
AND pds.PDID=properties.PDID
AND properties.ImageID=propertyimages.ImageID
AND properties.Status= 'Active'
AND properties.propertyStatus = 'APPROVED'
AND ProvinceName='".$this->provincename."'
AND DistrictName='".$this->districtname."'
AND PropertyDealType='".$this->propertystatus."'
GROUP BY properties.PropertyID";
// The query run in here
$queryrun = $this->connection->query($query);
// In here checks for the errors which may occure in our query
if( $this->connection->error )
exit( $this->connection->error );
$this->num_rows = $queryrun->num_rows;
// storing the value of the query into the variable of row
while ($res = $queryrun->fetch_assoc()) {
$array[] = $res;
}
// Return array or return 0 (false)
return (isset($array))? $array: 0;
}
}
}
// Start instance, feed in database connection
$_property = new ProvinceProp($connection);
// See if there are rows returned (greater than or equal to 0) or empty
// Empty signifies that criteria to generate the sql was not satisfied
$array = $_property->ProcessPost();
?><!DOCTYPE html>
<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="favico.ico">
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content=" spdealers Onlince Dealing," />
<meta name="Keywords" content="spdealers.com - spdealers, Property spdealers, Property spdealers, real estate Afghanistan, Afghanistan property, Afghanistan properties, property in Afghanistan, property Afghanistan, Afghanistan real estate, apartments, properties for sale Afghanistan, office space, property, buy property, sell property, rent property, commercial real estate Afghanistan, Afghanistan properties, Afghanistan properties on sale, Afghanistan property portals, Afghanistan residential real estate, rental property, flats, apartments, studio apartments, property site,makaan, makan, spdealers.com, real estate properties, Afghanistan real estate, real estate Afghanistan, property Afghanistan, Afghanistan property portal, buy property, sell property, rent property online, flats, apartments, studio apartment, rental property, commercial real estate, search property, list property, post requirement, featured builders, dealers, property index, properties in Afghanistan, property by localityProperty, Properties, Property For Sale, Find a Property, Properties for sale, Real Estate, Buy real estate. R">
<Meta name="description" content="spdealers Online Property Dealing In Afghansitan, Property Search, buy, sell, rent, lease residential, commercial propertys only on spdealers.com.">
<title>SPDealers</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<div id="wrapper">
<?php
// I am only guessing where conditions are met so display required....
if(isset($_property->provincename)) { ?>
<!--start header class -->
<div id="header">
<div id="logo"><img src="images/logo.png" alt="" /></div>
<ul>
<li class="selected"><span>PROPERTY</span></li>
<li>View Option</li>
<li><span>HOME</span></li
</ul>
</div>
<!--start body class -->
<div id="body">
<div class="header">
<div>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
<div>
<p>Do you want to earn money and have a good income? Do you want to receive money without working hours and putting pressure over your Mind, So Please contact with us and make yourself one of our valuable Remote Employee Click Here for more information.</p>
</div>
<div id="threeimages">
<img src="images/flags.png">
<img src="images/graph.png">
</div>
</div>
</div>
<div class="footer">
<div class="featured"><?php
// If the array was returned (ie rows were returned from db)
if(is_array($array)) {
// Here is the start of the loop where I am guessing it would be...??
foreach($array as $row) { ?>
<div class="propertywrapperviewmore">
<div class="propertysingleimageviewmore">
<a href="property.php?ImageID=<?php echo $row['ImageID'] ?>">
<img src="../Admin Panel/Property_Insertion_Files/<?php echo $row['ImagePath'] ?>" width="227" height="147" alt="<?php echo $row['ImageName'] ?>" style="border-radius:8px;" ></a>
</div>
<div class="propertyIDviewmorelablevalue">
<div class="propertyIDL">Property ID:</div>
<div class="propertyIDV"><?php echo $row['PropertyID']?></div>
<div align="right" style="width:310px; height:15px; font-size:20px; float:right; padding-bottom:5px; background-color:#000; color:#FFF;">
<marquee behavior="scroll" scrollamount="2" onMouseover="this.scrollAmount=1" onMouseout="this.scrollAmount=6"><?php echo $row['PropertyDealType'] ?></marquee>
</div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Property Type:</div>
<div class="propertyothersV"><?php echo $row['PropertyType']?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Address:</div>
<div class="propertyothersV"><?php echo $row['PropertyRegion'].' / Nahya: '.$row['PDName'].' / District: '.$row['DistrictName'].' / '.$row['ProvinceName']?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Total Price:</div>
<div class="propertyothersV">
<?php $price = (isset($row['PropostedPrice']) && $row['PropostedPrice']!='')? number_format($row['PropostedPrice'], 2, '.', ','):'';
echo $row['CurrencyType'].' '.$price?></div>
</div>
<div class="propertysviewmoreotherlablevalue" style="margin-bottom: 60px;">
<div class="propertyothersL">Deal Status:</div>
<div class="propertyothersV"><?php echo $row['DealStatus']?></div>
</div>
<div class="propertysviewmoreDescription">
<div class="propertysviewmoreDescriptionL">Description:</div>
<div class="propertysviewmoreDescriptionV">To find out more this property, please click on the VIEW MORE button. You can contact us more specific information on this property.
<label style="float:right;"><br>View More</label>
<div>
</div>
</div>
<?php }
} ?>
</div>
</div>
<?php }
if(isset($_property->num_rows) && $_property->num_rows == 0) { ?>
<div style='margin-left:116px; line-height: 36px;'>Sorry there is no Record for Your search: <br>
Province: <b><?php echo $provincename; ?></b> <br>District: <b><?php echo $districtname; ?></b>
<br> Property Status: <b><?php echo $propertystatus; ?></b>
<br> to search other provinces and cities<br>
<a href='../index.php' style='text-decoration:none; font-size: 16px; color:#2a4f5e;'>Click Here</a>
</div><?php
}
else { ?>
<br><br>You Havent Selected The Following Properly:<br><br>
<strong>(Province)</strong> <br>
<strong>(District)</strong> <br>
<strong>(Property Status)</strong>.<br><br>
Please <a href='../index.php' style='text-decoration:none; font-size: 16px; color:#2a4f5e;'>Click Here</a> to go back<?php
} ?>
</div>
<div id="ads" style="margin-left:844px;">
<div id="adsone"></div>
<div id="adsthree"></div>
</div>
</div>
</div>
<div id="footer">
<div id="bottomoptions">Home About Us Advertise With Us Terms&Condition Help&Support Privacy Policy FAQ Contact Us Report A Problem
<div id="copyright"><p>All rights Reserved©2014 spdealers.com</p></div>
</div>
</div>
</div>
</body>
</html>
Your code is written in while loop you have to add only those tag that you want to repeat to full HTML code.
<HTML CODE>
<?php code
While loop
{
//php and html code combine
}
?>
<HTMl CODE>
Try this. my comments are in the capital letters so read them,
Breif Explanation: I removed the header tag from your while posted it above while loop and leave the note how you can place it. According to your need. and some other code i also posted it above the while loop.
But before reading the solution look the example how the while loop work
while($condition)
{
//repeat the code. In short it will reapeat the code untill the condition is true. Thanks
}
Thats your answer
<?php
require_once('../Admin Panel/db.php');
if(!empty($_POST['Province']) && !empty($_POST['District']) && !empty($_POST['radio']))
{
$provincename=$_POST['Province'];
$districtname=$_POST['District'];
$propertystatus=$_POST['radio'];
$query = "SELECT
properties.PropertyID,
properties.PropertyType,
properties.PropertyDealType,
properties.PropertyRegion,
properties.PropostedPrice,
properties.DealStatus,
properties.CurrencyType,
propertyimages.ImageID,
propertyimages.ImagePath,
propertyimages.ImageName,
provinces.ProvinceName,
districts.DistrictName,
pds.PDName
FROM properties, provinces, districts, pds, propertyimages
WHERE provinces.ProvinceID=properties.ProvinceID
AND districts.DistrictID=properties.DistrictID
AND pds.PDID=properties.PDID
AND properties.ImageID=propertyimages.ImageID
AND properties.Status= 'Active'
AND properties.propertyStatus = 'APPROVED'
AND ProvinceName='".$provincename."'
AND DistrictName='".$districtname."'
AND PropertyDealType='".$propertystatus."'
GROUP BY properties.PropertyID";
$queryrun= $connection->query($query); // The query run in here
if( $connection->error ) exit( $connection->error ); // In here checks for the errors which may occure in our query
//PUT YOUR HTTML CODE HERE WHICH YOU DONT WANT TO GET REPEATED.
//END THE PHP HERE
?>
<!DOCTYPE html>
<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="favico.ico">
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content=" spdealers Onlince Dealing," />
<meta name="Keywords" content="spdealers.com - spdealers, Property spdealers, Property spdealers, real estate Afghanistan, Afghanistan property, Afghanistan properties, property in Afghanistan, property Afghanistan, Afghanistan real estate, apartments, properties for sale Afghanistan, office space, property, buy property, sell property, rent property, commercial real estate Afghanistan, Afghanistan properties, Afghanistan properties on sale, Afghanistan property portals, Afghanistan residential real estate, rental property, flats, apartments, studio apartments, property site,makaan, makan, spdealers.com, real estate properties, Afghanistan real estate, real estate Afghanistan, property Afghanistan, Afghanistan property portal, buy property, sell property, rent property online, flats, apartments, studio apartment, rental property, commercial real estate, search property, list property, post requirement, featured builders, dealers, property index, properties in Afghanistan, property by localityProperty, Properties, Property For Sale, Find a Property, Properties for sale, Real Estate, Buy real estate. R">
<Meta name="description" content="spdealers Online Property Dealing In Afghansitan, Property Search, buy, sell, rent, lease residential, commercial propertys only on spdealers.com.">
<title>SPDealers</title>
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="logo">
<img src="images/logo.png" alt="" />
</div>
<ul>
<li class="selected"><span>PROPERTY</span></li>
<!--ADDED THE HEADER HERE. YOU CAN PLACE IT WITH THE HELP OF YOUR CSS WHERE EVERY YOU WANT-->
<div class="header">
<div>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
<div>
<p>Do you want to earn money and have a good income? Do you want to receive money without working hours and putting pressure over your Mind, So Please contact with us and make yourself one of our valuable Remote Employee Click Here for more information.</p>
</div>
<div id="threeimages">
<img src="images/flags.png">
<img src="images/graph.png">
</div>
</div>
</div>
<?php
//BEFORE WHILE LOOP START AGAIN YOUR PHP
while ($row= $queryrun->fetch_assoc()) // storing the value of the query into the variable of row
{
$count= $queryrun->num_rows; // Taking the number of queries returened by the result
?>
<li>View Option</li>
<li><span>HOME</span></li>
</ul>
</div>
<div id="body">
<br>
<div class="footer">
<div class="featured">
<div class="propertywrapperviewmore">
<div class="propertysingleimageviewmore">
<a href="property.php?ImageID=<?php echo $row['ImageID'] ?>">
<img src="../Admin Panel/Property_Insertion_Files/<?php echo $row['ImagePath'] ?>" width="227" height="147" alt="<?php echo $row['ImageName'] ?>" style="border-radius:8px;" ></a>
</div>
<div class="propertyIDviewmorelablevalue">
<div class="propertyIDL">Property ID:</div>
<div class="propertyIDV"><?php echo $row['PropertyID']?></div>
<div align="right" style="
width:310px;
height:15px;
font-size:20px;
float:right;
padding-bottom:5px;
background-color:#000;
color:#FFF;
"><marquee behavior="scroll" scrollamount="2" onMouseover="this.scrollAmount=1" onMouseout="this.scrollAmount=6"><?php echo $row['PropertyDealType'] ?></marquee></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Property Type:</div>
<div class="propertyothersV"><?php echo $row['PropertyType']?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Address:</div>
<div class="propertyothersV"><?php echo $row['PropertyRegion'].' / Nahya: '.$row['PDName'].' / District: '.$row['DistrictName'].' / '.$row['ProvinceName']?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Total Price:</div>
<div class="propertyothersV"><?php $price = (isset($row['PropostedPrice']) && $row['PropostedPrice']!='')?
number_format($row['PropostedPrice'], 2, '.', ','):'';
echo $row['CurrencyType'].' '.$price?></div>
</div>
<div class="propertysviewmoreotherlablevalue">
<div class="propertyothersL">Deal Status:</div>
<div class="propertyothersV"><?php echo $row['DealStatus']?></div>
</div>
<br><br><br><br>
<div class="propertysviewmoreDescription">
<div class="propertysviewmoreDescriptionL">Description:</div>
<div class="propertysviewmoreDescriptionV">
To find out more this property, please click on the VIEW MORE button. You can contact us more specific information
on this property.
<label style="float:right;"><br>View More</label>
<div>
</div>
</div>
</div>
</div>
<?php
}
if($queryrun->num_rows == 0)
{
echo "<div style='margin-left:116px; line-height: 36px;'>".'Sorry there is no Record for Your search: '." ". "<br>
Province: <b>".$provincename."</b> <br>District: <b>". $districtname."</b>
<br> Property Status: <b>".$propertystatus."</b>
<br> to search other provinces and cities
<br>
<a href='../index.php' style='text-decoration:none; font-size: 16px; color:#2a4f5e;'>Click Here</a>
</div>";
}
}
else
{
echo '<br><br>You Havent Selected The Following Properly:<br><br>
<strong>(Province)</strong> <br>
<strong>(District)</strong> <br>
<strong>(Property Status)</strong>.<br><br>';
echo "Please <a href='../index.php' style='text-decoration:none; font-size: 16px; color:#2a4f5e;'>Click Here</a> to go back";
}
?>
</div>
<div id="ads" style="margin-left:844px;">
<div id="adsone"></div>
<div id="adsthree"></div>
</div>
</div>
</div>
<div id="footer">
<div id="bottomoptions">Home About Us Advertise With Us Terms&Condition Help&Support Privacy Policy FAQ Contact Us Report A Problem
<div id="copyright"><p>All rights Reserved©2014 spdealers.com</p>
</div>
</div>
</div>
</div>
</body>
</html>