Hi i am writing a balloon race site and i am having problems with some functions to calculate the distance the balloon travels firstly i am reading my info from the database using the fetch assoc function what i have is 2 table one for the race details and one for the postcode details what i am having problems with is listing all the races in the database then having a coloumn at the end which tell you how far the balloon has travelled i have the maths functions and in the race database i also have start and end postcodes what i need to know is how i can select a postcode from the race database based on row id and then match this with the postcode from the postcode database and also get the longitude and latitude details based on the postcode and is needs to do this for each row in the fetch assoc results this is what i have so far but i do know its not working and don't know how to correct it or if it is even possible.
[CODE=php]<?php
$query = "SELECT * FROM `duchy`";
$result = mysql_query($qu ery);
if ($result) {
while ($array= mysql_fetch_ass oc($result)) {
echo $array['startcode']. " - ". $array['finderspostcod e']. " - ". $array['ID'];
echo "<br />";
}
} else {
print "<li>No results.</li>";
}
?>
<?
$sql = 'SELECT DISTINCT `lat` FROM postcode as P,duchy as T WHERE `code` LIKE T.startcode AND T.ID = $array[ID] ';
$result=mysql_q uery($sql);
$lat1=mysql_fet ch_assoc($resul t);
$sql2 = 'SELECT DISTINCT `lon` FROM `postcode` WHERE `code` LIKE `$postcode` LIMIT 0 , 30';
$result2=mysql_ query($sql2);
$lon1=mysql_res ult($result2,"l on");
$sql3 = 'SELECT DISTINCT `lat` FROM `postcode` WHERE `code` LIKE `$endcode` LIMIT 0 , 30';
$result3=mysql_ query($sql3);
$lat2=mysql_res ult($result3,"l at");
$sql4 = 'SELECT DISTINCT `lon` FROM `postcode` WHERE `code` LIKE `$endcode` LIMIT 0 , 30';
$result4=mysql_ query($sql4);
$lon2=mysql_res ult($result4,"l on");
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($la t1)) * sin(deg2rad($la t2)) + cos(deg2rad($la t1)) * cos(deg2rad($la t2)) * cos(deg2rad($th eta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
echo "<td>";
echo " The value after formating = $miles<br></td></tr>";
?>
<?
echo '</table>'."\n";
?>[/CODE]
any help on this would be most appreciated.
[CODE=php]<?php
$query = "SELECT * FROM `duchy`";
$result = mysql_query($qu ery);
if ($result) {
while ($array= mysql_fetch_ass oc($result)) {
echo $array['startcode']. " - ". $array['finderspostcod e']. " - ". $array['ID'];
echo "<br />";
}
} else {
print "<li>No results.</li>";
}
?>
<?
$sql = 'SELECT DISTINCT `lat` FROM postcode as P,duchy as T WHERE `code` LIKE T.startcode AND T.ID = $array[ID] ';
$result=mysql_q uery($sql);
$lat1=mysql_fet ch_assoc($resul t);
$sql2 = 'SELECT DISTINCT `lon` FROM `postcode` WHERE `code` LIKE `$postcode` LIMIT 0 , 30';
$result2=mysql_ query($sql2);
$lon1=mysql_res ult($result2,"l on");
$sql3 = 'SELECT DISTINCT `lat` FROM `postcode` WHERE `code` LIKE `$endcode` LIMIT 0 , 30';
$result3=mysql_ query($sql3);
$lat2=mysql_res ult($result3,"l at");
$sql4 = 'SELECT DISTINCT `lon` FROM `postcode` WHERE `code` LIKE `$endcode` LIMIT 0 , 30';
$result4=mysql_ query($sql4);
$lon2=mysql_res ult($result4,"l on");
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($la t1)) * sin(deg2rad($la t2)) + cos(deg2rad($la t1)) * cos(deg2rad($la t2)) * cos(deg2rad($th eta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
echo "<td>";
echo " The value after formating = $miles<br></td></tr>";
?>
<?
echo '</table>'."\n";
?>[/CODE]
any help on this would be most appreciated.
Comment