Jump to content

Getting ALL values from a table


kaneos

Recommended Posts

I have a table with a list of towns and cities with their postcode and latitude and longitude. Since a lot of small towns in an area have the same postcode.

 

I have a search which I want to return all towns that have the same postcode.

 

the table is set up as:

 

postcode:::::::town::::::::lat:::::::::long

Link to comment
https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/
Share on other sites

<?php
//assuming postcode will be some value gathered from a post or get action.
$postcode="12345";
$listcitys = mysql_query("SELECT town,lat,long FROM postcodes WHERE postcode=$postcode");
WHILE($lstctys = mysql_fetch_array($listcitys)) {
$town=$lstctys['town'];
$lat=$lstctys['lat'];
$long=$lstctys['long'];
// you can list this in many ways.  I'll just echo
echo "Town: $town  Lat: $lat  Longitude: $long<br />";
}
?>

<?php

include "connectionfile.php";

$postcode = $_GET["postcode"];


$listcitys = mysql_query("SELECT town, lat, long FROM postcodes WHERE postcode=$postcode");
WHILE($lstctys = mysql_fetch_array($listcitys)) {
$town=$lstctys['town'];
$lat=$lstctys['lat'];
$long=$lstctys['long'];

echo "Town: $town  Lat: $lat  Longitude: $long<br />";
}
?>

I just realized that there was a conflict with having 'long' as a table field and have changed it to 'lng', this has made the town and latitude appear however the longitude will still not show up.

 

new source

 

<?php

include "connectionfile.php";



$postcode="2533";
$listcitys = mysql_query("SELECT town, lat, lng  FROM postcode WHERE postcode=$postcode");
WHILE($lstctys = mysql_fetch_array($listcitys)) {
$town=$lstctys['town'];
$lat=$lstctys['lat'];
$long=$lstctys['long'];

echo "Town: $town  Lat: $lat  Longitude: $long<br />";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.