Mongodb でサブ配列をどのようにソートすればよいのか疑問に思っています。
私は次のものを持っています
$cursor = $collection->find(array("_id"=>new MongoId($this->data['cid'])));
$cursor->sort(array("replied"=>array("replyid"=>1)));
if ($cursor->count() > 0)
{
$test = array();
// iterate through the results
while( $cursor->hasNext() ) {
$test[] = ($cursor->getNext());
}
return $test;
}
しかし、私は試してみ$cursor->sort(array("replied"=>array("replyid"=>0)));
まし$cursor->sort(array("replied"=>array("replyid"=>1)));
たが、成功しませんでした
foreachステートメントでそれを行う必要があるかどうか疑問に思っています
<?php
if($customersupport[0]['replies'] != NULL)
{
foreach($customersupport[0]['replies'] as $customer_reply)
{
?>
<div style="border-bottom:thin solid #666;">
<span style="color:#666;float:left; width:40%;">
<?php if($customer_reply['whoreplied'] == "user"){
$usertwo = $fetch->namesearch($customer_reply['uid']);
}else{
$usertwo = $fetch->adminnamesearch($customer_reply['uid']);
}
print $usertwo[0]['personalinfo']['firstname']." ".$usertwo[0]['personalinfo']['lastname'];
?></span><span style="float:right; width:40%; text-align:right;font-size:12px;"><?=$customer_reply['replydate'];?></span>
<br>
<?=$customer_reply['msg'];?>
</div>
<?php
}
}
?>
ここに私たちのmongodbのサンプルがあります
{
"_id": ObjectId("5XXXXXXXX000000"),
"issue": "test",
"replies": {
"0": {
"replyid"▼: ObjectId("5014cXXXXXXXXXX0000"),
"replydate": "29\/07\/2012CDT00: 18: 50",
"whoreplied": "user",
"uid": ObjectId("4fXXXXXXXXXXXXX00"),
"msg": "test"
}
},
"status": "Issued",
"subject": "test",
"uid": ObjectId("4XXXXXXXX000000")
}