View Single Post
10-03-2012, 02:28 AM
#1
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old  Populating Multi-Dimensional Array with timestamp

PHP Code:
        $db->query("SELECT ux.id as id, ux.exerciseid, ux.date as date, ux.notes, e.measurement, e.name
        FROM `users exercises` ux LEFT JOIN exercises as e ON e.id = ux.exerciseid
         WHERE `userid` = '
$memberid'
         ORDER BY date DESC LIMIT 20"
);

        while(
$row $db->fetch_assoc())
               
$aData[$row['id']] = array($row['date'], $row['id'], $row['name']);


        
print_r($aData); 
This outputs:

PHP Code:
    Array
(
    [
4] => Array
        (
            [
0] => 2012-10-03 02:44:38
            
[1] => 4
            
[2] => Double Kettlebell Press
        
)

    [
3] => Array
        (
            [
0] => 2012-10-03 02:11:13
            
[1] => 3
            
[2] => Elliptical Trainer
        
)

    [
2] => Array
        (
            [
0] => 2012-10-03 01:59:46
            
[1] => 2
            
[2] => Fencing
        
)

    [
1] => Array
        (
            [
0] => 2012-08-29 16:14:14
            
[1] => 1
            
[2] => Other Dancing
        
)


However I'm trying to nest the array by day:

PHP Code:
Array
(
    [
2012-10-03] => Array
    (

        [
3] => Array
            (
                [
0] => 2012-10-03 02:11:13
                
[1] => 3
                
[2] => Elliptical Trainer
            
)

        [
2] => Array
            (
                [
0] => 2012-10-03 01:59:46
                
[1] => 2
                
[2] => Fencing
            
)

        [
1] => Array
            (
                [
0] => 2012-10-03 02:44:38
                
[1] => 4
                
[2] => Double Kettlebell Press
            
)

        )

    [
2012-10-02] => Array
    (
        [
1] => Array
            (
                [
0] => 2012-08-29 16:14:14
                
[1] => 1
                
[2] => Other Dancing
            
)
    )

Any idea?

Reply With Quote