Calendar distance(zipcode), oddly when distance increased. Ideas?

I am writing a calendar script that returns all known auctions ending on a specific date at a specified distance from a zipcode.

So it should work as follows. User searches by distance from a zipcode, the script returns a calendar with the number of auctions ending displayed on the ending date. That works perfectly!

The problem lies when you increase the distance to greater than 5 miles. The greater the distance supplied the more calendars repeats itself down the page. if you do a distance of 5 miles you get 1 instances of the calendar, 6 you get 2 instances, 10 you get 8 instances and so on and so forth.

So I need an extra set of eyes, can anyone see where it is all going wrong?
[php]<?php
if($theMonth != $monthNames[$cMonth-1]){
echo “<a href=”.$_SERVER[“PHP_SELF”] . “?month=”. $prev_month . “&year=” . $prev_year.">Previous";
}
?>
<?php echo $monthNames[$cMonth-1].' '.$cYear; ?>
<a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>">Next

<div class="daysofweekrow">
	<div class="daysofweekcols">
		Sunday
	</div>
	<div class="daysofweekcols">
		Monday
	</div>
	<div class="daysofweekcols">
		Tuesday
	</div>
	<div class="daysofweekcols">
		Wednesday
	</div>
	<div class="daysofweekcols">
		Thursday
	</div>
	<div class="daysofweekcols">
		Friday
	</div>
	<div class="daysofweekcols">
		Saturday
	</div>
</div>
<?php $zip = $_GET['zip']; $distance = $_GET['distance']; if(preg_match('/^[0-9]{5}$/', $zip)){ if(preg_match('/^[0-9]{1,3}$/', $distance)){ require('includes/db_connect.php'); if(!$rs = mysqli_query($conn, "SELECT * FROM zipcode WHERE postal_code = '$zip'")) { echo "There was a database error attempting to retrieve your ZIP Code. Please try again.\n"; } else { if(mysqli_num_rows($rs) == 0) { echo "No database match for provided ZIP Code. Please enter a new ZIP Code.\n"; } else { //if found, set variables $row = mysqli_fetch_array($rs); $lat1 = $row['latitude']; $lon1 = $row['longitude']; $d = $distance; $r = 3959; //compute max and min latitudes / longitudes for search square $latN = rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(0)))); $latS = rad2deg(asin(sin(deg2rad($lat1)) * cos($d / $r) + cos(deg2rad($lat1)) * sin($d / $r) * cos(deg2rad(180)))); $lonE = rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(90)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN)))); $lonW = rad2deg(deg2rad($lon1) + atan2(sin(deg2rad(270)) * sin($d / $r) * cos(deg2rad($lat1)), cos($d / $r) - sin(deg2rad($lat1)) * sin(deg2rad($latN)))); $query = "SELECT * FROM zipcode WHERE (latitude <= $latN AND latitude >= $latS AND longitude <= $lonE AND longitude >= $lonW)"; if(!$rs1 = mysqli_query($conn, $query)) { echo "There was an error selecting nearby ZIP Codes from the database.\n"; } elseif(mysqli_num_rows($rs1) == 0) { echo "No nearby ZIP Codes located within the distance specified. Please try a different distance.\n"; } else { echo mysqli_error($conn); //output all matches to screen while($row = mysqli_fetch_array($rs1)) { $truedistance = acos(sin(deg2rad($lat1)) * sin(deg2rad($row['latitude'])) + cos(deg2rad($lat1)) * cos(deg2rad($row['latitude'])) * cos(deg2rad($row['longitude']) - deg2rad($lon1))) * $r; if($truedistance < $d) { $postal_code = $row['postal_code']; //build days $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; for ($i=0; $i<($maxday+$startday);$i++) { if(($i % 7) == 0 ){ echo '
'; } if($i < $startday){ echo '
 
'; } else { echo '
'. ($i - $startday + 1); $thedate = $cYear.'-'.$cMonth.'-'.($i - $startday + 1); $thedate = date('Y-m-d',strtotime($thedate)); $sql = mysqli_query($conn, "SELECT count(*) FROM auctions WHERE auction_zipcode = '$postal_code' AND auction_date = '$thedate'"); $row = mysqli_fetch_row($sql); echo ''.$row[0].'
'; } if(($i % 7) == 6 ){ echo "
"; } } } } } } } mysqli_close($conn); }else { echo 'Distance can not be greater than 999 miles'; } }else { echo 'This is not a number'; }[/php]

I feel like we are missing something here. If the calendar is added when you add distance, and this is the calendar code, what calls this? That should be where the problem lays.

Nope, nothing was missing, the only thing in the file above it was the style sheet.

But the post is now moot anyways, I fixed that problem and moved onto another. There seem to be many with this script.

The problem for those interested was where the call for the number of auctions for a given day was called from. It had to be done before the loop and then pulled out of an array for its usage on the calendar.

Needless to say the code doesn’t look ANYTHING like what I posted last night. But now functions as intended.

I am sure I will be back though, this script is a B*&$h! :o

Sponsor our Newsletter | Privacy Policy | Terms of Service