Reputation: 213
Im trying to create sort button for list but ive got this list, and i dont know what to do with this timestamp is it possible to sort with it, here is my array type, i hope you will help me guys here it it:
Array
(
[0] => 17
[ticket] => 17
[1] => Name Second Name
[author] => Name Second Name
[2] => modules
[subject] => modules
[3] => 1412335833
[timestamp] => 1412335833
[4] => 1414048041
[activity] => 1414048041
[5] => Closed
[type] => Closed
[6] => 3
[priority] => 3
[7] => 13
[assignment] => 13
[8] => 17
)
Array
(
[0] => 18
[ticket] => 18
[1] => Name Second Name
[author] => Name Second Name
[2] => modules
[subject] => modules
[3] => 1412335935
[timestamp] => 1412335935
[4] => 1414048095
[activity] => 1414048095
[5] => Closed
[type] => Closed
[6] => 3
[priority] => 3
[7] => 0
[assignment] => 0
[8] => 18
)
As you can see timestamp is the date. I need to sort it, here is what ive tried:
function date_compare($a, $b)
{
$t1 = strtotime($a['timestamp']);
$t2 = strtotime($b['timestamp']);
return $t1 - $t2;
}
usort($row, 'date_compare');
But i get error because of timestamp... Here is error Warning: Illegal string offset 'timestamp' in /home/...../domains/foxiad.com/public_html/...../modules/ticketsmith/index.php on line 365
Upvotes: 0
Views: 57
Reputation: 3743
The output of array you are showing here looks generated by this kind of thing, which are all seperate arrays.
while($row = mysql_fetch_row($variable))
{
print_r($row);
}
You need to build one seprate array, then perform a sort on it.
while($row = mysql_fetch_row($variable))
{
$results[] = $row;
}
Then, you will be able to sort that, feeding $results
to usort()
Upvotes: 1