开发者

How do you sort php and sql arrays?

How can I sort this array by city or by id i开发者_如何学Pythonn descending order?

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$city = mysql_result($result,$i,"city");
$state = mysql_result($result,$i,"state");
$id = mysql_result($result,$i,"id");

echo "$city";
echo "$state";

++$i; } } else { echo "No results."; } ?>


You didn't include your SQL code in the above post, but that is the part of the code where you are supposed to add the ORDER BY sorting function as follows:

SELECT * FROM address_table ORDER BY city desc


you can also use "LIMIT" for one city: SELECT * FROM address_table ORDER BY city desc LIMIT 0,1 - returns 1 row

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜