Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,256
Total Threads: 81,169
Total Posts: 566,838
There are 39 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Populating Multi-Dimensional Array with timestamp

Thread title: Populating Multi-Dimensional Array with timestamp
Reply    
    Thread tools Search this thread Display Modes  
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
10-03-2012, 02:38 AM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Try using

PHP Code:
$aData[$row['date']][] = array($row['date'], $row['id'], $row['name']); 

Reply With Quote
10-03-2012, 02:49 AM
#3
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

That will only change the name. I'm wanting to re-populate the array so each day has it's own nesting, with the rows for that day included.

Code:
			$key = explode(' ', $row['date']);
			$aData[$key[0]][] = array($row['date'], $row['id'], $row['name']);
Almost there. :P

Reply With Quote
10-04-2012, 10:54 PM
#4
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

Is the above the best solution? Don't want to be using bad practises.

Reply With Quote
10-04-2012, 11:11 PM
#5
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

I don't see anything wrong with it.

Reply With Quote
Reply    


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed