$get_id = "SELECT distinct a.listingsdb_id
FROM bkkapart_en_listingsdbelements a, bkkapart_classlistingsdb b
WHERE a.listingsdbelements_field_name = 'city'
and a.listingsdb_id = b.listingsdb_id
and b.class_id = $select_type
ORDER BY a.listingsdb_id ";
if ( ( $Page > $Num_Pages ) || ( $Page < 0 ) )
print "Number $Page more than $Num_Pages";
while($result = mysql_fetch_array($db_query1))
{
$sql = "SELECT DISTINCT a.listingsdb_id,(SELECT
b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'city'
AND b.listingsdb_id = a.listingsdb_id ) AS fcity,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'Area'
AND b.listingsdb_id = a.listingsdb_id ) AS fArea,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'beds'
AND b.listingsdb_id = a.listingsdb_id ) AS fbeds,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'price'
AND b.listingsdb_id = a.listingsdb_id ) AS fprice,
(SELECT b.listingsdbelements_field_value
FROM bkkapart_en_listingsdbelements b
WHERE b.listingsdbelements_field_name = 'home_features'
AND b.listingsdb_id = a.listingsdb_id) AS ffeatures,
c.listingsdb_title AS ftitle,
d.listingsimages_thumb_file_name AS fpicture
FROM bkkapart_en_listingsdbelements a, bkkapart_en_listingsdb c, bkkapart_en_listingsimages d
WHERE a.listingsdb_id = $result[listingsdb_id]
AND a.listingsdb_id = c.listingsdb_id
AND c.listingsdb_id = d.listingsdb_id
AND d.listingsimages_rank = '1' ";