kiwimediapro
-
Posts
6 -
Joined
-
Last visited
Never
Posts posted by kiwimediapro
-
-
Hi guru's,
I have a particular problem i cant seem to get the better of it. I just cant see the solution.
I have the code bellow which itterates through an array to create a 3 column table for each year with x no of rows of data and a Totals row to sum each column. The totals have been done via sql and are already in the array dso no need to calculate them just display them as a table footer for each year.
Problem is that because that it misses doing the first year totals and attaches the second years to the first and so on. I beleive the issue is with my iteration loop writing out the HTML but cant see it. :-)
Below is the code
<?php if( !empty($data)){ //$lastmonth=NULL; $lastyear = NULL; foreach($data as $row) { if ($row['year'] != $lastyear) { echo (!$lastyear==NULL ? " <tfoot><tr style='font-weight:bold;font-size:12px'><td>Totals</td><td>".$row['year_totalsales']."</td><td>$".$row['year_amount']."</td></tr></tfoot></table></div>" : NULL); echo " <h3><a href='#'>",$row['year']," - Total Amount ",$row['year_totalsales']," Total Sales $",$row['year_amount'],"</a></h3><div><table width='100%'><tr><th colspan=3></th></tr><tr><th>Month</th><th>Amount</th><th>Sales</th></tr>"; $lastyear = $row['year']; } echo "<tr><td>", $row['month'], "</td><td>", $row['month_amount'], "</td><td>", $row['month_total_sales'], "</td></tr>"; }//--end foreach //$lastyear = NULL; // if ($row['year'] != $lastyear) { //echo (!empty($lastyear)) ? '</table></div>' : NULL; echo " <tfoot><tr style='font-weight:bold;font-size:12px'><td>Totals</td><td>",$row['year_totalsales'],"</td><td>$",$row['year_amount'],"</td></tr></tfoot>"; //} echo "</table></div>"; } ?>
-
Hi,
Ihave the below array output from a DB query. I need to convert into the bottom array for Google CHarts. Any ideas?
$myarray = array(
0 => array( 'year' => 2009, 'month' => "January", 'month_sales' => 524, 'year_totalsales' => 3610 ),
1 => array ( 'year' => 2009, 'month' => 'February', 'month_sales' => 521, 'year_totalsales' => 3610 ),
2 => array ( 'year' => 2009, 'month' => 'March', 'month_sales' => 501, 'year_totalsales' => 3610 ),
3 => array ( 'year' => 2009, 'month' => 'April', 'month_sales' => 601, 'year_totalsales' => 3610 ),
4 => array ( 'year' => 2009, 'month' => 'May', 'month_sales' => 710, 'year_totalsales' => 3610 ),
5 => array ( 'year' => 2009, 'month' => 'June', 'month_sales' => 801, 'year_totalsales' => 3610 ),
6 => array ( 'year' => 2009, 'month' => 'July', 'month_sales' => 991, 'year_totalsales' => 3610 ),
7 => array ( 'year' => 2009, 'month' => 'August', 'month_sales' => 301, 'year_totalsales' => 3610 ),
8 => array ( 'year' => 2009, 'month' => 'September', 'month_sales' => 250, 'year_totalsales' => 3610 ),
9 => array ( 'year' => 2009, 'month' => 'October', 'month_sales' => 322, 'year_totalsales' => 3610 ),
10 => array ( 'year' => 2009, 'month' => 'November', 'month_sales' => 621, 'year_totalsales' => 3610 ),
11 => array ( 'year' => 2009, 'month' => 'December', 'month_sales' => 691, 'year_totalsales' => 3610 ),
12 => array ( 'year' => 2010, 'month' => "January", 'month_sales' => 789, 'year_totalsales' => 1610 ),
13 => array ( 'year' => 2010, 'month' => "February", 'month_sales' => 1409, 'year_totalsales' => 1610 ),
14 => array ( 'year' => 2010, 'month' => "March", 'month_sales' => 550, 'year_totalsales' => 1610 )
);
raw_data=[['January',524,0],['February',521,0],['March',501,0],['April',601,0],['May',710,0],['June',801,0],
['July',991,0],['August',301,0],['September',250,0],['October',322,0],['November',621,0],['December',691,0],['January',789,0],['February',1409,0],['March',550,0],];
raw_data= [ [ month1 , year1 sales figure(zero if no figure), year2 sales figure(zero if no figure).....], [ month1 , year1 sales figure(zero if no figure), year2 sales figure(zero if no figure).....]......];
Thanks all
-
YEs it works! All hail the PHP guru . ...... :-)
Using the same array code i need to create a javascript array for Google Charts Like this:
raw_data=[['May',1429,0],['June',1565,0],['July',1581,0],['August',1437,0],['September',627,0],['October',660,0],['November',524,0],['December',521,0],['January',0,609],['February',0,619],['March',0,732],['April',0,605]];
Where:
raw_data= [ [ month1 , year1 sales figure(zero if no figure), year2 sales figure(zero if no figure).....], [ month1 , year1 sales figure(zero if no figure), year2 sales figure(zero if no figure).....]......];
-
Woohoo! I htink youve done it. Teting and let you know.
-
Hi,
I have the following code so far :
<? $myarray = array( 0 => array( 'year' => 2009, 'month' => "November", 'month_sales' => 524, 'year_totalsales' => 3610 ), 1 => array ( 'year' => 2009, 'month' => 'December', 'month_sales' => 521, 'year_totalsales' => 3610 ), 2 => array ( 'year' => 2010, 'month' => "January", 'month_sales' => 609, 'year_totalsales' => 3610 )); $lastyear = ""; echo "<table><tr><th>Month</th><th>Sales</th></tr>", PHP_EOL; foreach($myarray as $row) { if ($row['year'] != $lastyear) { echo "<tr><th colspan=2>", $row['year'], "</th></tr>", PHP_EOL; $lastyear = $row['year']; } echo "<tr><td>", $row['month'], "</td><td>", $row['month_sales'], "</td></tr>", PHP_EOL; } echo "</table>", PHP_EOL; ?>
BUt this code gives me this:
<table><tr><th>Month</th><th>Sales</th></tr> <tr><th colspan=2>2009</th></tr> <tr><td>November</td><td>524</td></tr> <tr><td>December</td><td>521</td></tr> <tr><th colspan=2>2010</th></tr> <tr><td>January</td><td>609</td></tr> </table>
Instead of this:
<table><tr><th>Month</th><th>Sales</th></tr> <tr><th colspan=2>2009</th></tr> <tr><td>November</td><td>524</td></tr> <tr><td>December</td><td>521</td></tr> </table> <table><tr><th>Month</th><th>Sales</th></tr> <tr><th colspan=2>2010</th></tr> <tr><td>January</td><td>609</td></tr> </table>
ANy help appreciated thx
Array iteration to tablr creation issue
in PHP Coding Help
Posted
Yes! That is exactly the issue. But I no not how to fix it. :-)