Hi, I'm currently working on a project where i need to get some values from a database (easy). Code: $query = mysql_query("SELECT * FROM details") Then i need to work out the distance using eastings & northings from the OS datapack (easy). Code: while($details = mysql_fetch_array($query)) { ..code... $distance = getDistance($u_easting, $u_northing, $c_easting, $c_northing) } Code: $distance [B] Could give a number like 101.262 or 12.344[/B] I'm getting stuck where i need to order the allowed values (under a certain range) and display them... Any ideas, all i can think of is reentering them into a temp database and pulling them out in order, but idealy i want to avoid this as it is too time consuming? Thanks in advance... Marty
You can add your distances to the array as follows: Code: $distance_arr[] = $distance1; $distance_arr[] = $distance2; ... And then you could use the sort or rsort functions: http://www.php.net/manual/en/function.sort.php http://www.php.net/manual/en/function.rsort.php
Thanks, that seems to work well, how would i display them? Theres mysql_fetch_array(), would this work with a made up array, i think not? I would like it to be like while($row = ) { blah blah } Thanks for your help! Marty
Ok, i have an array like this: Code: Array ( [0] => Array ( [CID] => 14 [distance] => 9.82 ) How can i echo ['distance'] IF CID = 14 ?? I currently have: Code: echo $cid_array[14]['distance']; But this brings back the row 14, which, after sorting is different to the CID... Thanks Marty
Fixed, thanks for your help! Code: foreach($cid_array as $column => $result) { if ($result['CID'] == "$CID") { echo $result['distance']." Miles<br>"; } }