display_area_updater.php
<?php
include('include/db_con.php');
if (!$radius){
$radius = '1';
}
$get_lat = "SELECT AVG(latitude) FROM zipcodes WHERE city = '$city' AND state = '$state'";
$got_lat = mysql_query($get_lat);
$rowlat = mysql_fetch_array($got_lat);
$lat = $rowlat[0];
$get_lon = "SELECT AVG(longitude) FROM zipcodes WHERE city = '$city' AND state = '$state'";
$got_lon = mysql_query($get_lon);
$rowlon = mysql_fetch_array($got_lon);
$lon = $rowlon[0];
$coords = array('latitude' => $lat, 'longitude' => $lon);
$sql = "SELECT DISTINCT city, ( 3959 * acos( cos( radians( {$coords['latitude']} ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( {$coords['longitude']} ) ) + sin( radians( {$coords['latitude']} ) ) * sin( radians( latitude ) ) ) ) AS distance FROM zipcodes HAVING distance <= {$radius} ORDER BY distance";
$query = mysql_query($sql);
//while($row = mysql_fetch_assoc($query)){
//$selected_cities = $row['city'];
//echo "$$" . $selected_cities . "$$<br />";
$names = array();
while ($row = mysql_fetch_array($query)) {
$names[] = $row[0];
}
$selected_cities = implode("' or '", array_unique($names));
//echo "{$row['city']} {$row['zipcode']} ({$row['distance']})<br>\n";
//echo $selected_cities;
$Get_City = mysql_query("SELECT rest_id FROM restaurant_info WHERE state = '$state' AND city = ('$selected_cities') ORDER BY rest_id");
$rest_ids = array();
while ($got_city = mysql_fetch_array($Get_City)) {
$rest_ids[] = $got_city[0];
}
print_r(array_values($rest_ids));
echo "<form name='mark_sold' action='mark_sold.php' enctype='multipart/form-data' method='post'><table width='1100' border='1'><tr><td><h2>Spot 1</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space1 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space1'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font>";
}else{
$is_sold = "<font color='green'>available</font><input name='ad1' id='ad1' type='checkbox' value='1'/><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
echo "</td><td><h2>Spot2</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
echo $id;
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space2 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space2'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font>";
}else{
$is_sold = "<font color='green'>available</font><input name='ad2' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
echo "</td><td><h2>Spot 3</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space3 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space3'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font>";
}else{
$is_sold = "<font color='green'>available</font><input name='ad3' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
echo "</td><td><h2>Spot 4</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space4 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space4'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font>";
}else{
$is_sold = "<font color='green'>available</font><input name='ad4' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
echo "</td><td><h2>Spot 5</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space5 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space5'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font>";
}else{
$is_sold = "<font color='green'>available</font><input name='ad5' type='checkbox' value='1' /><input name='rest_id' type='hidden' value='" .$rest_id."' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
echo "</td></tr><tr><td><h2>Spot 6</h2>";
foreach ($rest_ids as $id){
//$rest_ids = implode("' or '", $rest_ids);
//$rest_ids = "'" . $rest_ids . "'";
$Get_Ad = mysql_query("SELECT rest_id, rest_name, city, ad_space6 FROM restaurant_info WHERE rest_id = $id");
$got_ad = mysql_fetch_assoc($Get_Ad);
$is_sold = $got_ad['ad_space6'];
$rest_id = $got_ad['rest_id'];
$rest_name = $got_ad['rest_name'];
$city = $got_ad['city'];
if($is_sold){
$is_sold = "<font color='red'>sold</font>";
}else{
$is_sold = "<font color='green'>available</font><input name='ad6' type='checkbox' value='1' />";
}
echo $rest_name." in ". $city." is ".$is_sold."<br />";
}
//blah blah blah
echo "</td></tr><tr><td colspan='5'><center><input type='submit' name='submit' value='Submit'></center></td></tr></table></form>";
mysql_close();
?>