kaneos Posted October 20, 2011 Share Posted October 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/ Share on other sites More sharing options...
MasterACE14 Posted October 20, 2011 Share Posted October 20, 2011 are the cities in a different table? and what is the name of the table above? I'm assuming you're using MySQL. MySQL SELECT syntax Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280740 Share on other sites More sharing options...
kaneos Posted October 20, 2011 Author Share Posted October 20, 2011 the table name is postcodes, the cities are all under the towns column. yes I am using MySQL Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280742 Share on other sites More sharing options...
Drummin Posted October 20, 2011 Share Posted October 20, 2011 <?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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280758 Share on other sites More sharing options...
kaneos Posted October 20, 2011 Author Share Posted October 20, 2011 I have just put this into a php file with the connection file included and it does not seem to want to print anything out on the page. any suggestions? I have been through and checked that all my table fields match up. Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280770 Share on other sites More sharing options...
litebearer Posted October 20, 2011 Share Posted October 20, 2011 please show us YOUR code Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280786 Share on other sites More sharing options...
kaneos Posted October 20, 2011 Author Share Posted October 20, 2011 <?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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280798 Share on other sites More sharing options...
kaneos Posted October 20, 2011 Author Share Posted October 20, 2011 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280808 Share on other sites More sharing options...
litebearer Posted October 20, 2011 Share Posted October 20, 2011 didn't carry change thru to here $long=$lstctys['long']; Quote Link to comment https://forums.phpfreaks.com/topic/249437-getting-all-values-from-a-table/#findComment-1280826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.