| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,532
|
help with multidimensional array
Can nayone help please? Why does this not work? // create UKPostCodes array $result = mysql_query("SELECT * FROM UKPostCodes",$db); if ($myrow = mysql_fetch_array($result)) { do { $UKPostCodes = array ('$myrow[PostCode]' => array('$myrow[Lat]','$myrow[Long]')); } while ($myrow = mysql_fetch_array($result)); } // get from array lat1 and long1 $lat1 = $UKPostCodes['$_POST[Fpostcode]'][1]; $long1 = $UKPostCodes['$Fpostcode'][2]; I am assuming that '$UKPostCodes = array' starts a new empty array everytime so I end up with just one row? Is that right? If so how do I get around it? Thanks. |
|
|
|
|
|
#2 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,532
|
To clarify, I want to get the entries from a db of postcodes with latitude and longtitude values into an array. Then pull out a value $lat1 and $long1 based on the postcode posted by a form $Fpostcode. |
|
|
|
#7 (permalink) | ||
|
Grumpy old man
Join Date: Oct 2007
Location: North Japan
Posts: 1,376
|
Quote:
I fucking hate it when people who don't have a clue just spout random useless shit. Quote:
Remove all the single quotes from the line and it'll work. $UKPostCodes = array($myrow[PostCode]=>array($myrow[Lat],$myrow[Long])); |
||
|
|
|
#9 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,532
|
Thanks Hunch, I am pretty sure I tried that every which way. I don't think is possible to append to a mdim array in that way. I will play with it again later when I have a bit of time. In the end I used a simple assoc array where the second half holds two values split by a recognised string. I could only do this because I know the data format is fixed. $UKPostCodes[$myrow[PostCode]] = $myrow[Lat]."xxx".$myrow[Long]; Then split them out where needed. $latlong1 = $UKPostCodes[$Fpostcode]; $latlong1 = explode("xxx",$latlong1); $lat1 = $latlong1[0]; $long1 = $latlong1[1]; |
|
|
|
#10 (permalink) | |
|
Grumpy old man
Join Date: Oct 2007
Location: North Japan
Posts: 1,376
|
Quote:
By removing the quotes? I tested it to be sure. It's fine. |
|
|
|
|
#11 (permalink) |
|
Spare Parts
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,532
|
Thanks. As you can probably guess I am working on system to compare a postcode to the contents of a database and return the nearest results. I think I have to revisit the mdim array to sort the results nearest first. |
|
![]() |