How to put data of each month in its respective monthly column

195
June 24, 2017, at 6:28 PM

I'm still learning, please help me

I have this code that will show monthly statistics. How do I put each data of each month in its respective column?

This is what I got so far.

$result= $myDB->query("SELECT * FROM ".$myDB->prefix("statistics")." WHERE year='2017'") or die(mysql_error()); 
while($row = $myDB->fetchArray($result))
{
$id=$row['id'];
$year=$row['year'];
$sum=$row['sum'];
$january=$row['january'];
$february=$row['february'];
$march=$row['march'];
$april=$row['april'];
$may=$row['may'];
$june=$row['june'];
$july=$row['july'];
$august=$row['august'];
$september=$row['september'];
$october=$row['october'];
$november=$row['november'];
$december=$row['december'];
}

echo "<table class='table table-striped table-bordered'><thead><tr>";
echo "<th class='text-center'>Year</th>";
for($m=1; $m<=12; ++$m){
    $monthName=date('M', mktime(0, 0, 0, $m, 1)).'<br>';
echo "<th class='text-center'>$monthName</th>";
}
echo "</tr></thead>";
echo "<tr>";
echo "<td class='text-center'>$year</td>";
for($m=1; $m<=12; ++$m){
echo "<td class='text-center'> data </td>";
}
echo "</tr>";
echo "</table>";
Answer 1

As you are storing data in month name vaiable you can get it using $$ try this:

echo "<table class='table table-striped table-bordered'><thead><tr>";
echo "<th class='text-center'>Year</th>";
for($m=1; $m<=12; ++$m){
    $monthName=date('M', mktime(0, 0, 0, $m, 1));
echo "<th class='text-center'>$monthName</th>";
}
echo "</tr></thead>";
echo "<tr>";
echo "<td class='text-center'>$year</td>";
for($m=1; $m<=12; ++$m){
    $monthName=strtolower(date('F', mktime(0, 0, 0, $m, 1)));
echo "<td class='text-center'>".$$monthName." </td>";
}
Rent Charter Buses Company
READ ALSO
How to check did laravel update a table?

How to check did laravel update a table?

Below I need to update some columns in the users tableI use laravel query builder in code

317
How to implement Apache Rewrite Rule correctly?

How to implement Apache Rewrite Rule correctly?

Following is my rewrite rule code written in thehtaccess file placed in the

274
Enter quotes and double quotes in a html textarea without an insertion operation fail in database. Is it possible?

Enter quotes and double quotes in a html textarea without an insertion operation fail in database. Is it possible?

In my site I have a textarea whose text is inserted into a field in my databaseI would like to be able to enter quotation marks and quotes without the insertion operation in the database fail

275
Wordpress - Call to function in a separate file

Wordpress - Call to function in a separate file

In my wordpress functionsphp I have declared the following file inside a function:

268