473,465 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Postcode Calculator

3 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $query = "SELECT * FROM `duchy`";
  3.  
  4. $result = mysql_query($query);
  5.  
  6. if ($result) {
  7.  
  8.     while ($array= mysql_fetch_assoc($result)) {
  9.                 echo $array['startcode']. " - ". $array['finderspostcode']. " - ". $array['ID'];
  10.     echo "<br />";
  11.  
  12.  
  13.     }
  14.  
  15. } else {
  16.  
  17.     print "<li>No results.</li>";
  18.  
  19. }
  20.  
  21.  
  22.  
  23.  
  24. ?>
  25. <?
  26. $sql = 'SELECT DISTINCT `lat` FROM postcode as P,duchy as T WHERE `code` LIKE T.startcode AND T.ID = $array[ID] '; 
  27. $result=mysql_query($sql);
  28. $lat1=mysql_fetch_assoc($result);
  29. $sql2 = 'SELECT DISTINCT `lon` FROM `postcode` WHERE `code` LIKE `$postcode` LIMIT 0 , 30';
  30. $result2=mysql_query($sql2);
  31. $lon1=mysql_result($result2,"lon");
  32. $sql3 = 'SELECT DISTINCT `lat` FROM `postcode` WHERE `code` LIKE `$endcode` LIMIT 0 , 30';
  33. $result3=mysql_query($sql3);
  34. $lat2=mysql_result($result3,"lat");
  35. $sql4 = 'SELECT DISTINCT `lon` FROM `postcode` WHERE `code` LIKE `$endcode` LIMIT 0 , 30';
  36. $result4=mysql_query($sql4);
  37. $lon2=mysql_result($result4,"lon");
  38.  
  39.  
  40. $theta = $lon1 - $lon2; 
  41.   $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
  42.   $dist = acos($dist); 
  43.   $dist = rad2deg($dist); 
  44.   $miles = $dist * 60 * 1.1515;
  45.   echo "<td>";
  46.   echo " The value after formating = $miles<br></td></tr>";
  47.  
  48. ?>
  49. <?
  50.  
  51.  
  52.  
  53.  
  54.             echo '</table>'."\n";
  55.  
  56.  
  57.  
  58.  
  59. ?>
any help on this would be most appreciated.
Jul 4 '07 #1
5 2334
Atli
5,058 Recognized Expert Expert
Hi, billynastie2007, and welcome to TSDN!

First of all, they put a dot button on your keyboard for a reason! Please use it :)

I'm not sure what data you are working with. Could you show us the layout of those tables your using?
Jul 4 '07 #2
RedSon
5,000 Recognized Expert Expert
Hi, billynastie2007, and welcome to TSDN!

First of all, they put a dot button on your keyboard for a reason! Please use it :)

I'm not sure what data you are working with. Could you show us the layout of those tables your using?
You mean the period button right?
Jul 5 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, billynastie.

What is your code doing? Give an example.
What is your code supposed to be doing? Give an example.
Jul 7 '07 #4
billynastie2007
3 New Member
Hi
Thankyou for your replies.
What i am doing is writing a simple website for a balloon race and what i am trying to do is run a php maths function on a database query for each row in the database.
I can get it to output the maths function results per row but what i am trying to get it to do is write the results of the maths function back to the database relating to each row.
Heres what i have so far.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $hostname = "localhost"; // The Thinkhost DB server. 
  3. $username = "tech0000_main"; // The username you created for this database. 
  4. $password = "admin"; // The password you created for the username. 
  5. $usertable = "test"; // The name of the table you made. 
  6. $dbName = "tech0000_balloon"; // This is the name of the database you made. 
  7.  
  8. MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
  9. @mysql_select_db( "$dbName") or die( "Unable to select database"); 
  10. ?> 
  11. <?php
  12. // Make a MySQL Connection
  13. $query = "SELECT * FROM duchy"; 
  14.  
  15. $result = mysql_query($query) or die(mysql_error());
  16.  
  17. echo "<table border='3' cellpadding='3' bordercolor='#000000'>\n<tr>\n" .
  18.                "\n\t<th>Distance Covered</th>" .
  19.  
  20.  
  21.           "\n</tr>";
  22. while($row = mysql_fetch_array($result)){
  23. echo "\n<tr>";
  24.  
  25.     $lat1=$row['startlat'];
  26. $lon1=$row['startlon'];
  27. $lat2=$row['endlat'];
  28. $lon2=$row['endlon'];
  29.  
  30. $theta = $lon1 - $lon2; 
  31.   $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); 
  32.   $dist = acos($dist); 
  33.   $dist = rad2deg($dist); 
  34.   $miles = $dist * 60 * 1.1515;
  35.   echo"<td>" .number_format($miles,2);
  36.   ?>
  37.   <?
  38.   echo"- Miles</font></td>";
  39.  
  40.  
  41.     echo "<br />";
  42.  
  43. }
  44.  
  45. ?>
The bit that is underlined is the maths function this calculates the distance between 2 points based on longitude and latitude when this script is run against the database it outputs the mileage based on information in each row but i need to save the results this creates back to the database to create a leaderboard.

Here is the table struture for the mysql database.

-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 22, 2007 at 12:55 AM
-- Server version: 5.0.41
-- PHP Version: 5.2.2

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `tech0000_balloon`
--

-- --------------------------------------------------------

--
-- Table structure for table `duchy`
--

CREATE TABLE `duchy` (
`kidsfirstname` varchar(255) collate latin1_general_ci NOT NULL,
`kidslastname` varchar(255) collate latin1_general_ci NOT NULL,
`findersfirstname` varchar(255) collate latin1_general_ci NOT NULL,
`finderslastname` varchar(255) collate latin1_general_ci NOT NULL,
`findersaddress` varchar(255) collate latin1_general_ci NOT NULL,
`finderspostcode` varchar(255) collate latin1_general_ci NOT NULL,
`findersemail` varchar(255) collate latin1_general_ci NOT NULL,
`endlat` varchar(255) collate latin1_general_ci NOT NULL,
`endlon` varchar(255) collate latin1_general_ci NOT NULL,
`endloc` varchar(255) collate latin1_general_ci NOT NULL,
`finderscontact` varchar(255) collate latin1_general_ci NOT NULL,
`startcode` varchar(255) collate latin1_general_ci default 'M6',
`startloc` varchar(255) collate latin1_general_ci NOT NULL default 'Salford',
`startlat` varchar(255) collate latin1_general_ci NOT NULL default '53.492',
`startlon` varchar(255) collate latin1_general_ci NOT NULL default '-2.297',
`miles` varchar(255) collate latin1_general_ci NOT NULL,
`ID` int(25) NOT NULL auto_increment,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=37 ;

--
-- Dumping data for table `duchy`
--

INSERT INTO `duchy` VALUES ('John', 'doe', 'Jane', 'Doe', '10', 'E17', '', '51.586', '-0.019', 'Walthamstow', '0161', 'm6', 'Salford', '53.492', '-2.297', '36.510334425', 23);
INSERT INTO `duchy` VALUES ('Emiy', 'Harrison', '', '', '', 'LS10', '', '53.762', '-1.531', 'Leeds', '', 'm6', 'Salford', '53.492', '-2.297', '36.51', 24);

The full working site can be found here Balloon Race race id is duchy.

Thanks for any help you can assist with its most appreciated.
Jul 21 '07 #5
billynastie2007
3 New Member
Heya, billynastie.

What is your code doing? Give an example.
What is your code supposed to be doing? Give an example.
Hi Ive re-issued the code and a description for the help i need.
Jul 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Lapchien | last post by:
I have a field for a postcode. I'd like another field to auto contain an 'area' number, based on the first part (only) of the postcode. For example, if a postcode LS4 4DJ was entered, another...
5
by: Alan | last post by:
Hi, I'm getting as bit confused with my queries. I simply (!) want to insert a space into a postcode field the 4th character from the right, so, for example, ML201TQ becomes ML20 1TQ, which is...
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
6
by: Julian | last post by:
Hi, I am a very beginner in databases. I created a database table in Access 2003 and OOo 2.03 that includes name, address, postcode, phone numbers etc of our customers. I would like to sort...
3
by: mark | last post by:
I have a table of UK companies whose records I want to filter using a map of postcode regions. For the benfit of people outside the UK, our postcodes are a pain to work with because they are not...
12
by: xhe | last post by:
I am now developing a website which needs Canadian PostCode Database. I can certainly buy one, but that will cost my hundered of $$, and my website is only for education purpose, it won't make...
0
by: Pinna | last post by:
Hiya, I am trying to select based on a range on postcode on a table. The field POSTCODE is a varchar2(8). The problem is when refinng on 'where postcode between 'PE1' and 'PE29'', because this is...
1
by: dominicowen | last post by:
Hi, I have a customer database in Access 2003 with customers postcodes. What I want to do is type in a postcode on access and it will link the postcode on to googlemaps without having to type...
3
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.