1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
| <?php
mysql_select_db($database_classifieds, $classifieds);
function inradius($zip,$radius)
{
$query="SELECT * FROM zip_codes WHERE zip='$zip'";
//echo $query."<br>";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$lat=$row["latitude"];
$lon=$row["longitude"];
$query="SELECT zip FROM zip_codes WHERE (POW((69.1*(longitude-\"$lon\")*cos($lat/57.3)),\"2\")+POW((69.1*(latitude-\"$lat\")),\"2\"))<($radius*$radius) ";
//echo $query;
$result = mysql_query($query);
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$zipArray[]=$row;
}
return $zipArray;
}
} else {
return "Zip Code not found";
}
} // end func
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_search = $main['maxRows_search'] ;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
$pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;
mysql_select_db($database_classifieds, $classifieds);
//handle the options//
$inSQL="";
$count=0;
foreach(@$_GET as $objItem => $objValue){
if(substr($objItem,0,3)=="opt" && $objValue<>""){
$inSQL .= "'". $objValue ."',";
$count++;
}
}
$inSQL.="''";
if($count>0){
$addSQL="INNER JOIN products_fields ON products.id = products_fields.pID AND sValue IN (".$inSQL.") ";
}
if(isset($_GET['zipCode']) && $_GET['zipCode']<>""){
$zipCode = trim(@$_REQUEST["zipCode"]);
if(isset($_REQUEST['miles']) && $_REQUEST['miles']<>""){
$radius = $_REQUEST["miles"];
}else{
$radius = 2500;
}
$zipArray = inRadius($zipCode,$radius);
print "<h2>There are ".count($zipArray)." Zip codes within $radius Miles of $zipCode</h2>";
$i=1;
foreach($zipArray as $row) {
if(count($zipArray)==$i)
$zipSQL.="'".$row[zip]."'";
else
$zipSQL.="'".$row[zip]."',";
$i++;
}
$query_search="SELECT products.id,products.owner,products.title,products.featured,products.section,products.description,products.price,products.dateadded,products.expiration, products.annonceur,products.descriptionlongue, products.departement, products.codepostal, products.ville FROM products LEFT JOIN users ON products.owner=users.id WHERE products.expiration > NOW() AND products.display='Y' AND users.zip IN (".$zipSQL.")";
//echo $sql;
} else {
$query_search="SELECT products.id,products.owner,products.title,products.featured,products.section,products.description,products.price,products.dateadded,products.expiration, products.annonceur, products.ville, products.departement, products.codepostal, products.descriptionlongue FROM products LEFT JOIN users ON products.owner=users.id WHERE products.expiration > NOW() AND products.display='Y'";
}
$query_search="SELECT products.id, products.hitcount, products.prodID, products.owner, products.title, products.featured, products.section, products.description, products.price,products.dateadded, products.expiration, products.annonceur, products.codepostal, products.ville, products.caution, products.departement, products.descriptionlongue, users.city, users.address, users.zip, users.email, users.extra, users.firstname, users.lastname, users.phone FROM products ".$addSQL." LEFT JOIN users ON products.owner=users.id WHERE products.expiration > NOW() AND products.display = 'Y'";
// mon probleme se pose ici ******************************************************
$departement = preg_replace("`^0`", "", $_GET['departement']);
$departementdeux = preg_replace("`^0`", "", $_GET['departementdeux']);
if(!empty($departement) && !empty($departementdeux)) $query_search .= " AND products.departement LIKE $departement";
if(!empty($departementdeux) && !empty($departement)) $query_search .= " OR products.departement LIKE $departementdeux";
// mon probleme se pose ici ******************************************************
$codepostal = @$_GET['codepostal'];
if ($codepostal != '')
{
$query_search .= " AND products.codepostal = '$codepostal'";
}
$descriptionlongue = @$_GET['descriptionlongue'];
if ($descriptionlongue != '')
{
$query_search .= " AND products.descriptionlongue = '$descriptionlongue'";
}
$ville = @$_GET['ville'];
if ($ville != '')
{
$query_search .= " AND products.ville = '$ville'";
}
$annonceur = @$_GET['annonceur'];
if ($annonceur != '')
{
$query_search .= " AND products.annonceur = '$annonceur'";
}
//fin de la modif
$type = @$_GET['type'];
if ($type != '')
{
$query_search .= " AND products.section = '$type'";
}
$state=@$_GET['state'];
if($state != ''){
$query_search .= " AND users.state = '$state'";
}
$city=@$_GET['city'];
if($city != ''){
$query_search .= " AND users.city LIKE '%". $city ."%'";
}
//search price//
$minprice=trim(@$_GET['minprice']);
$maxprice=trim(@$_GET['maxprice']);
if($minprice == "")
$minprice=0;
if($maxprice == "")
$maxprice=9999999;
$query_search .= " AND products.price BETWEEN ". $minprice ." AND ". $maxprice;
//end search price
$owner = @$_GET['owner'];
if ($owner != '')
{
$query_search .= " AND products.owner = '".$owner."'";
}
$searchtext = @$_GET['searchtext'];
if ($searchtext != '')
{ // Some search text was specified
$query_search .= " AND (products.title LIKE '%".$searchtext."%' OR products.description LIKE '%".$searchtext."%')";
}
$query_search .= " GROUP BY products.id, products.owner, products.title, products.featured, products.section, products.description, products.price, products.annonceur, products.ville, products.descriptionlongue, products.departement, products.codepostal, products.dateadded, products.expiration";
if($count>0){
$query_search.=" HAVING count(sValue) = ".$count;
}
$query_search .= " ORDER BY ".$config['mainProductSort']." ".$config['mainProductSortOption']."";
#echo $query_search."<br>";
$query_limit_search = sprintf("%s LIMIT %d, %d", $query_search, $startRow_search, $maxRows_search);
$search = mysql_query($query_limit_search, $classifieds) or die(mysql_error());
$row_search = mysql_fetch_assoc($search);
if (isset($_GET['totalRows_search'])) {
$totalRows_search = $_GET['totalRows_search'];
} else {
$all_search = mysql_query($query_search);
$totalRows_search = mysql_num_rows($all_search);
}
$totalPages_search = ceil($totalRows_search/$maxRows_search)-1;
$queryString_search = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_search") == false &&
stristr($param, "totalRows_search") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_search = "&" . implode("&", $newParams);
}
}
$queryString_search = sprintf("&totalRows_search=%d%s", $totalRows_search, $queryString_search);
$maxRows_search = 10;
$pageNum_search = 0;
if (isset($_GET['pageNum_search'])) {
$pageNum_search = $_GET['pageNum_search'];
}
$startRow_search = $pageNum_search * $maxRows_search;
?> |
Partager