Darkmatter5 Posted October 28, 2008 Share Posted October 28, 2008 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? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 28, 2008 Share Posted October 28, 2008 Try using the explode() function. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 28, 2008 Share Posted October 28, 2008 <?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; ); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.