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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.