Jump to content

Automatic table problem


Icebergness

Recommended Posts

I'm trying to create a table that looks like this:

 

25/11/201128/09/201202/08/2013

23/12/201126/10/201230/08/2013

20/01/201223/11/201227/09/2013

17/02/201221/12/201225/10/2013

16/03/201218/01/201322/11/2013

13/04/201215/02/201320/12/2013

11/05/201215/03/201317/01/2014

08/06/201212/04/201314/02/2014

06/07/201210/05/201314/03/2014

03/08/201207/06/201311/04/2014

31/08/201205/07/201309/05/2014

 

Basically it formats the dates automatically every 4 weeks into 3 columns. So far, I have the following code:

 

<?php
$startDate = '2011-11-25';
$columns = 3;
$number_of_dates = 33;

// calculate number of rows per column
$rows_per_column = ceil($number_of_dates / $columns);
// make your table
echo "<table>\n";

//here we changed the condition to $i < $rows
for($i = 0; $i < $rows_per_column; $i++) {

echo "<tr>\n";

//here will run another loop for the amount of columns
for($j = 0; $j < $columns; $j++) 
{
	$weekOffset = $i * 4;
    	$nextDate = strtotime("{$startDate} +{$weekOffset} weeks");
    	echo "<td width = '100'>" . date('d/m/y', $nextDate) . "</td>\n";
    }
echo "</tr>\n";
}
echo "</table>\n";
?>

 

Which creates the first column fine, but then repeats the same column two more times...

 

25/11/201125/11/201125/11/2011

23/12/201123/12/201123/12/2011

20/01/201220/01/201220/01/2012

17/02/201217/02/201217/02/2012

16/03/201216/03/201216/03/2012

13/04/201213/04/201213/04/2012

11/05/201211/05/201211/05/2012

08/06/201208/06/201208/06/2012

06/07/201206/07/201206/07/2012

03/08/201203/08/201203/08/2012

31/08/201231/08/201231/08/2012

 

I know that this means there is a problem with my loop resetting itself rather than continuing, but I'm not sure how to fix it. Please could someone point out my stupid mistake?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/260198-automatic-table-problem/
Share on other sites

Hi CPD,

 

It is adding 4 weeks every time. Every column should display 11 dates (so column 1 works perfectly), and column 2 should carry on where column 1 left off. It's this that is the problem, it isn't carrying on, it's starting again.

 

Thanks

Archived

This topic is now archived and is closed to further replies.

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