You are here: Re: Sorting an Array - CSORT « PHP Programming Language « IT news, forums, messages
Re: Sorting an Array - CSORT

Posted by Nel on 11/29/05 12:21

> Can you post the all code you're having trouble with, instead of just a
> couple of lines?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex@attglobal.net
> ==================

Here is the code I am using - I have managed to get the code to re-create
two temp arrays and output the distance and userid in distance order, but
this seems very messy and longwinded.

See below

<?php

mysql_select_db($database_exampleDB, $exampleDB);
$query_numUsers = sprintf("SELECT dest.outcode, dest.x, dest.y, u.* FROM
postcodes AS source, postcodes AS dest, hotels AS u WHERE
source.outcode ='%s' AND ((dest.x <= (source.x + %s) AND dest.x >=
(source.x -
%s)) AND (dest.y <= (source.y + %s) AND dest.y >= (source.y - %s))) AND
u.outcode = dest.outcode AND u.fullname != '%s' ORDER BY dest.outcode ASC",
$colname_numUsers,$r_numUsers,$r_numUsers,$r_numUsers,$r_numUsers,$user_numUsers);
$numUsers = mysql_query($query_numUsers, $exampleDB) or die(mysql_error());

$row_numUsers = mysql_fetch_assoc($numUsers);
$totalRows_numUsers = mysql_num_rows($numUsers);

$sql = "SELECT * FROM postcodes WHERE outcode = '$Soutcode'";
$sqlresult = mysql_query($sql,$exampleDB) or die(mysql_errno());
$r = mysql_fetch_array($sqlresult);
$num_rows = mysql_num_rows($sqlresult);

$locX = $r[x];
$locY = $r[y];

echo "$totalRows_numUsers<p>";

if ($totalRows_numUsers > 0) { $temp = mysql_data_seek($numUsers, 0); }
$temp = 0;
while ($row_numUsers = mysql_fetch_assoc($numUsers)) {
$temp++;
$lid = $row_numUsers[id];
$netX = ($row_numUsers[x] - $locX);
$netY = ($row_numUsers[y] - $locY);
$hypotm = sqrt(($netX * $netX) + ($netY * $netY));
$hypotm = $hypotm / 1000 * 0.62 * 1.3;
$hypotm = number_format($hypotm,1);
$distance[$lid] = $hypotm;
$clist[$temp] = $lid;
}

if ($totalRows_numUsers > 0) { $temp = mysql_data_seek($numUsers, 0); }
$row_numUsers = mysql_fetch_assoc($numUsers);

array_multisort($distance, SORT_ASC, $clist);

$temp = 0;
foreach($distance as $dvalue) {

echo $dvalue." - ".$clist[$temp]."<br>";

$temp++;
}


?>

Outputs:

6

2.1 - 6 (distance - userid)
2.1 - 106
55.2 - 71
55.9 - 26
57.1 - 85
58.9 - 24

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация