Link to home
Start Free TrialLog in
Avatar of j8547
j8547

asked on

Display 2 months data - PHP

I want a webpage that displays 2 months of data. Current month and last month. So right now I would like it to display all of December in 1 table and all of January (currently to 10th and each day new data would add on until end of Jan). On Feb 1st, Dec will disappear and it will show Jan in 1 table and Feb in another and so on.....

I have inherited a web page were it used to show data and it would disappear at the end of the day. I don't know now how to change it to what i need. I have attached the file. Currently it only has 1 table with data. I thought if I figured out how to do current month then i could just add another table with current month -1...

Any help appreciated.
index.php
SOLUTION
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just answered this question phrased as ONE selection rather than two.  Looks like Jan offered the same solution given the different problem definition.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of j8547
j8547

ASKER

This works perfectly. Just 1 more question.... Can I get the tables side by side??

Also can you remove the output as i didn't realize the logo name would appear. Thanks
Avatar of j8547

ASKER

I also wanted to add a table at the top with the total amounts for each division (1 to 4). This would be the totals from the database from start to present not just last 2 months. I can post another questions if that is the best way. Thanks
I have updated the post to remove the logo and name.

To make them side by side you can use something like Bootstrap which allows you to do that.
Or you could simply put each table in a div with style
div.table-box
{
    box-sizing: border-box;
    width: 50%;
    float: left;
}
div.table-box:after {
   display: table;
   content: " ";
   clear: both;
}

Open in new window

I would put the table code into a function and call it in each block.
As for the other question about another table - best to open another question and refer to this one.
Avatar of j8547

ASKER

I know this questions is closed but just because you helped with the code. Instead of putting tables side by side I kept them on top of each other. But I want current month on top. Is it easy to manipulate your code to do this or do I need to change it alot as in split out the records as i call them from the database...?
You would need to change the query to order the the dates descending and then change the logic around the cutoff to be > than the last day of the previous month.
So cutoff would become

$cutoff = date('Y-m-t', strtotime('-1 month');

Open in new window


If you need more detail then open another question and refer to this one.