//******************* CONFIG ***********************
include('configfile.php');
mysql_connect($mysql_server,$mysql_username,$mysql_password);
mysql_select_db($mysql_database);
//**************************************************
//Process input data
$query = $_GET['q'];
$page = $_GET['p'];
$minprice = $_GET['minprice'];
$maxprice = $_GET['maxprice'];
//Get total pages
if($query != '')
{
if($maxprice != '')
{
$sqlsearchquery = "SELECT * FROM $scrap_tablename WHERE mls LIKE '%$query%' OR location LIKE '%$query%' AND rowprice > '$minprice' AND rowprice < '$maxprice' ORDER BY sold_date DESC";
}else{
$sqlsearchquery = "SELECT * FROM $scrap_tablename WHERE mls LIKE '%$query%' OR location LIKE '%$query%' AND rowprice > '$minprice' ORDER BY sold_date DESC";
}
$totalres = mysql_query($sqlsearchquery);
}else{
if($maxprice != '')
{
$sqlsearchquery = "SELECT * FROM $scrap_tablename WHERE rowprice > '$minprice' AND rowprice < '$maxprice' ORDER BY sold_date DESC";
}else{
$sqlsearchquery = "SELECT * FROM $scrap_tablename WHERE rowprice > '$minprice' ORDER BY sold_date DESC";
}
$totalres = mysql_query($sqlsearchquery);
}
if($query != '' or $minprice != 0 or $maxprice != 'unlimited')
{
$pagelabel = '(Showing recently sold)';
}else{
$pagelabel = '(Showing all listings)';
}
$totalitems = mysql_num_rows($totalres);
$maxpage = (int)($totalitems / $items_per_page);$maxpage = $maxpage+1;
//Addthis code
$addthis = '
';
//Page info
if($page <1 or $page > $maxpage){$page=1;}
$startfrom = $page-1;$startfrom = $startfrom*$items_per_page;
$result = mysql_query($sqlsearchquery." LIMIT $startfrom,$items_per_page");
$table = '';
if(mysql_num_rows($result) != 0)
{
while($row = mysql_fetch_array($result))
{
//Prepare pictures
if($row['pictures'] != 0)
{
$picture = 'pictures/'.$row['id'].'_0.jpg';
$currentpic = 1;
}else{
$picture = 'images/nopic.jpg';
$currentpic = 0;
}
//Prepare More-Info links
if($row[multimedia_link] == 'Not Available')
{
$moreinfolink = 'Not Available';
}else{
$mlink = @parse_url($row[multimedia_link]);
if($mlink == ''){
$mlink = 'Not Available';
$moreinfolink = ''.$mlink.'';
}else{
$moreinfolink = ''.$mlink[host].'';
}
}
//Config Addthis
$location = strip_tags(str_replace('
',' ',$row[location]));
$addthis_code = $addthis;
$addthis_code = str_replace('[#THE_MLS#]',$row[mls],$addthis_code);
$addthis_code = str_replace('[#THE_TITLE#]',$location,$addthis_code);
$addthis_code = str_replace('[#THE_DESCRIPTION#]',$row[description],$addthis_code);
//Create table
$listings .=
'
';
}
}else{
$listings = 'No results to show
';
}
###Create pags control bar###
//[FIRST] and [PREVIOUS] links
if($page == 1){
$first_link = '';
$previous_link = '';
}else{
$prevpage = $page-1;
if($query == ''){
$first_link = 'First | ';
$previous_link = 'Previous | ';
}else{
$first_link = 'First | ';
$previous_link = 'Previous | ';
}
}
//[NEXT] and [LAST] links
if($page == $maxpage){
$next_link = '';
$last_link = '';
}else{
$nextpage = $page+1;
if($query == ''){
$next_link = 'Next | ';
$last_link = 'Last';
}else{
$next_link = 'Next | ';
$last_link = 'Last';
}
}
//PAGES links
//Leftside
if($page != 1)
{
$leftp = array();
$c=0;
for($i=$page-1;$i>0;$i--)
{
if($c < 9)
{
$leftp[$c] = $i;
$c++;
}
}
sort($leftp);
if($query != ''){$qparam = '&q='.$query;}
for($i=0;$i'.$leftp[$i].' | ';
}
}
//Rightside
if($page != $maxpage)
{
$rightp = array();
$c=0;
for($i=$page+1;$i<$maxpage+1;$i++)
{
if($c < 9)
{
$rightp[$c] = $i;
$c++;
}
}
if($query != ''){$qparam = '&q='.$query;}
for($i=0;$i'.$rightp[$i].' | ';
}
}
if($page == $maxpage){$separator='';}else{$separator=' | ';}
$pagscontrol = $first_link.$previous_link.$pagesleft.$page.$separator.$pagesright.$next_link.$last_link;
###END OF [Create pags control bar]###
### [Prepare Max and Min price list] ###
$pricelist = array('25000','50000','75000','100000','125000','150000','175000','200000','225000','250000','275000','300000','325000','350000','375000','400000','425000','450000','475000','500000','550000','600000','650000','700000','750000','800000','850000','900000','950000','1000000','1500000','2000000','2500000','3000000','4000000','5000000','7500000','10000000');
//Generate option list [Min Price]
for($i=0;$i'.$formated.'';
}
//Generate option list [Max Price]
for($i=0;$i'.$formated.'';
}
###END OF [Prepare Max and Min price list] ###
?>
MLS
echo $listings;?>
echo $pagscontrol;?>