Jump to content

date variables help


Darkmatter5

Recommended Posts

Here's the query I have that returns the below result

$query=mysql_query("SELECT bill_name, bill_date_due, bill_amount
  FROM items
  WHERE folder_id=2
  ORDER BY bill_date_due ASC
  ") or die(mysql_error());

$dataset=mysql_fetch_array($query)

 

$dataset contains

bill_name

bill_due_date

bill_amount

tel01

2008-10-15

100

tel02

2008-11-15

120

 

Now how can I create another array that would break out the month and year of each set?

 

Example:

Array
(
[tel01] => Array
  (
  [year] => 2008
  [month] => 10
  [amount] => 100
  )
[tel02] => Array
  (
  [year] => 2008
  [month] => 11
  [amount] => 120
  )
)

 

Then say I want to echo the month of tel01, how would I do that?

Link to comment
https://forums.phpfreaks.com/topic/130489-date-variables-help/
Share on other sites

<?php
$query=mysql_query("SELECT bill_name, bill_date_due, bill_amount
  FROM items
  WHERE folder_id=2
  ORDER BY bill_date_due ASC
  ") or die(mysql_error());

$array = array();
while (list($bill, $date, $amt) = mysql_fetch_row($query))
{
    $t = strtotime($date);
    $array[$bill] = array (
                         'year'   => date('Y', $t);
                         'month'  => date('m', $t);
                         'amount' => $amt;
                    );

}
?>

Link to comment
https://forums.phpfreaks.com/topic/130489-date-variables-help/#findComment-677006
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.