【发布时间】:2013-12-08 19:34:00
【问题描述】:
我是 php 的新手,我不知道如何很好地使用数组。这是交易,我想将我从数据库中获得的三个或更多值添加到多维数组中,然后我想根据时间戳(其中一个值)对它们进行排序。之后,我想显示所有排序的值。我似乎无法做到这一点,这是代码
$queryWaitingPatients = 'SELECT ArrivalTime, TargetTime, Order, Classification FROM exams WHERE (CurrentState = "Pending")';
$results = mysql_query($queryWaitingPatients) or die(mysql_error());
if (mysql_num_rows($results) == 0) {
echo '<p>There\'s currently no patient on the waiting list.</p>';
return;
}
while ($rows = mysql_fetch_array($results)) {
extract($rows);
//now is the part that I don't know, putting the values into an array
}
// I'm also not sure how to sort this according to my $TargetTime
asort($sortedTimes);
//the other part I don't know, showing the values,
感谢您的帮助!
【问题讨论】:
-
仅供参考:
order是 reserved word。用反引号括起来或使用其他词,例如Orders。 -
为什么不在 sql 查询中使用 ORDER BY?这样数据就已经排序了。
标签: php sql arrays sorting multidimensional-array