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
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 />";
}
?>

Link to comment
Share on other sites

<?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 />";
}
?>

Link to comment
Share on other sites

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 />";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.