私のDBの列をプリントアウトし、私のために "Profit"という列を追加するこのコードがあります。 距離は複雑な方法で計算され、ループで行われますが、距離の「利益」への変換は印刷されたとおりに行われます。PHPの配列で並べ替える
私がしたいことは、「利益」の降順で印刷することです。私は、最良の方法は配列にそれらを格納し、そこに並べ替えてそこからそれらを印刷することであると(しかしわからない)と信じています。
アレイのどの行を固定するにはどうすればよいですか?
配列をソートするにはどうすればよいですか?
アレイをループバックして印刷できないようにするにはどうすればよいですか?
//display results
// now we retrieve the routes from the db
$query = "SELECT * FROM routes ORDER BY `id`;";
// run the query. if it fails, display error
$result = @mysql_query("$query") or die('<p class="error">There was an unexpected error grabbing routes from the database.</p>');
?>
<tr>
<td style="background: url(http://www.teamdelta.byethost12.com/barbg.jpg) repeat-x top;">
<center><b><font color="#F3EC84">»Matches«</font></b></center>
</td>
</tr>
<tr>
<td style="background: #222222;">
</font>
<table border="0" width="100%"><tr>
<td width="10%"><b><center><b>Player</b></center></b></td>
<td width="10%"><center><b>Base</b></center></td>
<td width="10%"><b>Location</b></td>
<td width="5%"><b>Econ</b></td>
<td width="10%"><b>Distance</b></td>
<td width="10%"><center><b>Profit cred./h</b></center></td>
<td width="40%"><b>Comment</b></td>
<td width="5%"><align="right"><b>Delete</b></align></td>
</tr>
<?
// while we still have rows from the db, display them
while ($row = mysql_fetch_array($result)) {
$dname = stripslashes($row['name']);
$dbase = stripslashes($row['base']);
$dlocation = stripslashes($row['location']);
$dx = stripslashes($row['x']);
$dy = stripslashes($row['y']);
$dgalaxy = stripslashes($row['galaxy']);
$dplanet = stripslashes($row['planet']);
$dcomment = stripslashes($row['comment']);
$did = stripslashes($row['id']);
$decon = stripslashes($row['econ']);
$distance = -1 ;//default
//distance calc
if($dgalaxy == $galaxy)
{//interstellar
if(($dx == $x) && ($dy == $y))
{//inter planitary
if ((floor($planet/10)*10) == (floor($dplanet/10)*10))
{// intra planitary loonar
$distance = abs(fmod($planet,10)-fmod($planet,10))*0.1;
}
else
{// inter planitary
$distance = abs((floor($planet/10)*10)-(floor($planet/10)*10))*0.2;
}
}else
{//interstllar
$distance = round(Sqrt(pow(($dx-$x),2)+pow(($dy-$y),2)));//interstllar
}
}
else
{//intergalatic
if ((floor($galaxy/10)*10) == (floor($dgalaxy/10)*10))
{//intra galactic cluster
$distance = abs(($galaxy-$dgalaxy))*200;
}
else
{//inter galactic cluster
if ($galaxy < $dgalaxy)
{//anti clockwise inter galactic cluster
$distance = (((9-fmod($galaxy,10))*200)+2000+(fmod($dgalaxy,10)*200));
}
else
{//clockwise inter galactic cluster
$distance = (((fmod($galaxy,10))*200)+2000+(fmod(9-$dgalaxy,10)*200));
}
}
}
echo('<tr>
<td width=\'20px\'><center>('.$dname.')</center></td>
<td><center>'.$dbase.'</center></td>
<td><a href="http://delta.astroempires.com/map.aspx?loc='.$dlocation.'">'.$dlocation.'</a></td>
<td>'.$decon.'</td><td>'.$distance.' </td>
<td>'.round(Sqrt(min($decon,$econ))*(1+Sqrt($distance)/75+Sqrt($players)/10)).'</td>
<td>['.$dcomment.']</td>
<td><a href=deleterouteconfirm.php?id='.$did.'>Delete</a></td>
</tr>');
}
?></table><!--display results table-->
それをすべて入力していただきありがとうございますが、動作していないようです。適切な時間が経過しても空白が表示されます。ここで動作しますか?http://www.teamdelta.byethost12.com/postroute.php D03:53:32:21を場所として使用し、文字列のコメントとプレイヤーはオプションです – Arthur
問題が見つかりました。 "$ safeForHtml = array_map( 'htmlspecialchars'、$ resultSet);"と$ resultSetから出力され、印刷されます。 – Arthur
okソーターが変更され、配列のリバースとその作業が削除されました。ありがとう – Arthur