Jump to content

only display if there are items in the table available


FUNKAM35

Recommended Posts

Hi, I have the following code to randomly select featured items.

 

there are sales sale_rent ='s'

 

and rentals sale_rent ='h'

 

 

i only want the items to dispaly if there are sale_rent ='s' in the table

or if there are sale_rent ='h' in the table

some countries may have only sales

some countries may have only rentals

 

not every country has both sales and rentals

if the country has only rentals then i only want sale_rent ='h' to display

 

if the country has only sales then i only want sale_rent ='s' to display

 

here is the code thanks

 

<?php
$select = "SELECT prop_id FROM property WHERE country= '$country' AND sale_rent ='s' AND ref <> 'GP' ";
$result=mysql_query($select);
$number_rows=mysql_num_rows($result);
if($number_rows > 2){
$count=3;
}else{
    $count=$max;
}
$max=$number_rows;
settype($max, "integer");
$min=0;
for($i=0;$i<=$count;$i++){
$limit=rand($min,$max);

$select = "SELECT prop_id, ref, price, prop_type, town, province, country, location, image1 FROM property WHERE country= '$country' AND sale_rent ='s' LIMIT $limit, 1";
$results = mysql_query($select, $link_id);
$query_data = mysql_fetch_row($results);
$prop_id = $query_data[0];
$ref = $query_data[1];
$price=($query_data[2]);
$prop_type= $query_data[3];
$town= $query_data[4];
$province = $query_data[5];
$country = $query_data[6];
$location = $query_data[7];
$url = $query_data[8];
$url=trim($url);                                                                                                                                                
$image_name="$url";
echo"<td style=\"width:14%; border:#033387 solid 1px; padding:2px;\"><p class=\"featdesc\">For Sale<br />$location<br />$town<br />$province<br />$country<br />$prop_type</p><a href=\"property_sale.php?id=$ref_number\" title='$prop_type $province $country'><img src=\"$image_name\" width=\"150\" height=\"112\" class=\"featureimage2\" alt=\"$prop_type $province\" /></a><p class=\"pricefeat\">\n";
if ($pound>0)
{
$price_dis ="£". number_format($pound);
}
if($pound==0)
{
$price_dis ="&#8364;". number_format($price);
}
echo"$price_dis</p></td>\n";

}
echo"</tr><tr>\n";
$select = "SELECT prop_id FROM property WHERE country= '$country' AND sale_rent ='h'";
$result=mysql_query($select);
$number_rows=mysql_num_rows($result);
if($number_rows > 2){
$count=3;
}else{
    $count=$max;
}
$max=$number_rows;
settype($max, "integer");
$min=0;
for($i=0;$i<=$count;$i++){
$limit=rand($min,$max);
$select = "SELECT prop_id, ref, price, prop_type, location, town, province, country, image1, sale_rent, rate1, rate2, rate3, currency FROM property WHERE country= '$country' AND sale_rent ='h' LIMIT $limit, 1";
$results = mysql_query($select, $link_id);
$query_data = mysql_fetch_row($results);
$prop_id = $query_data[0];
$ref = $query_data[1];
$price=($query_data[2]);
$prop_type= $query_data[3];
$location= $query_data[4];
$town= $query_data[5];
$province = $query_data[6];
$country = $query_data[7];
$url = $query_data[8];
$sale_rent= $query_data[9];
$rate1=$query_data[10];
$rate2=$query_data[11];
$rate3=$query_data[12];
$currency=$query_data[13];
$url=trim($url);
$image_name="$url";
$rate=$rate3;
if($rate==0)$rate=$rate2;
if($rate==0)$rate=$rate1;
if($rate==0)$rate=" on application";
$symbol="€";
$period=" per Week";
if($sale_rent=='l')$period=" per Month";
if($currency=='p')$symbol= "£";
echo"<td style=\"width:14%; border:#033387 solid 1px; padding:2px;\"><p class=\"featdesc\">Holiday Rentals<br />$location<br />$town<br />$province<br />$country<br />$prop_type</p><a href=\"property_holiday.php?id=$ref_number\" title='$prop_type $province $country rental'><img src=\"$image_name\" width=\"150\" height=\"112\" class=\"featureimage2\" alt=\"$prop_type $province\" /></a><p class=\"pricefeat\">From<br />$symbol $rate<br />$period</p></td>\n";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.