CSV Define Two Variables Based on Row Number Containing Month

Hi,

I am trying to display information from a CSV file where I want to show the rows where the information is contained within two rows containing the word of the current month. This works and shows as expected when manually inputting the values (141 and 157 in the code below), but I would prefer to define these values dynamically.
[php] echo “<table align=“center”>\n\n”;
$f = fopen(“STAMP HOLIDAY SICKNESS.csv”, “r”);
$i = 0;
$monthName = strtoupper(date(‘F’));
while (($line = fgetcsv($f)) !== false){
$i ++;
echo “

”;
				foreach ($line as $cell) {
					
					do
					{
						if ($i >= 141 && $i < 157){
							--PERFORM CODE HERE
						}
					}while(0);
						
				}
				echo "</tr>\n";
			}
			fclose($f);
			echo "\n</table>";[/php]

I have tried to define the variables using the code below, but this obviously only creates one variable and gets overwritten by the latest value. Any suggestions how to do this would be much appreciated.

[php] do
{
if ($line[0] == $monthName)
{
$lineNo = $i;
echo $lineNo ."
";
}
}while(0);[/php]

Thanks for your help

What does the csv look like? Nested loops are going to be a long term issue for your performance.

The csv is like the below for the current month and as mentioned this appears twice in the csv and acts like bookends for the data I want to retrieve:
NOVEMBER 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Any suggestions?

What is the csv? That looks like a calendar file

It is providing the function of a calendar. I want to display information between the two instances of NOVEMBER, do you know how I could define this two row variables?

NOVEMBER 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
Person 1 1 1 1 1 1

NOVEMBER 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

This sounds like a really bad idea that someone thought was genius.

So, based on the example. You have months and days surrounding people. The 1 identifies a persons attendance, or something on that particular day?

And this is a CSV not a tab delimited? So, if a person didn’t do anything on 1 Nov there is an empty space that keeps like graph consistent?

Yes, that’s correct :frowning:

Sponsor our Newsletter | Privacy Policy | Terms of Service