php - How to sort a massive/object
723
I've got a massive$events
.
To output information of this massive I do:
<?php foreach ($this->events as $usern): ?><?php foreach ($usern as $user): ?>
<tr>
<td><?php echo $user['id']; ?></td>
<td><?php echo $user->resource_types; ?></td>
<td><?php echo $user->resource_ids; ?></td>
<td><?php echo $user->action; ?></td>
<td><?php echo $this->owner($user->originator); ?></td>
<td><?php echo $user->event_date; ?></td>
<td>
<?php //if($this->canManageBusiness($user->id)): ?>
<?php // endif ?>
</td>
</tr>
<?php endforeach ?><?php endforeach ?>
Interesting that I may use both$user->id
and$user['id']
sintax. But never mind.
How can I sort this massive by$user['id']
desc?
Edited: I take data from database, but not usual way, so I can't use sql syntax so sort results:
$events[] =$this->_dbTable->fetchAll($this->_dbTable->select()->from($this->_dbTable, array('id','resource_types','resource_ids','action','originator','event_date'))->where('resource_types = ?', 'business')->where('resource_ids',$bus->id));
$events[] =$this->_dbTable->fetchAll($this->_dbTable->select()->from($this->_dbTable, array('id','resource_types','resource_ids','action','originator','event_date'))->where('resource_types = ?', 'document-type')->where('resource_ids',$dt->id));
return $events
Answer
Solution:
Do you read the data from a database? then simply add to your query
SORT BY id DESC
else you may use usort() in PHP:
Answer
Solution:
adding an
order()
to the query doesn't get you there?it looks to me like this is all coming from the same table, if so why not build a single query?
Maybe something like:
Not real sure if this will help get you there, maybe.
Answer
Solution:
This sucks, since you have to go through the list twice, but you could...
Now you can use events arr, which is sorted by user_id
Answer
Solution:
Decided to denormolise my DB Table to make the process of selection data easier. Let's see if it get's better.