Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

What is the problem with my WHILE loop?

$
0
0

I have created this WHILE loop inside a javascript function to pull a range of data from corresponding mysql records.

 

It is supposed to grab the year header and range of values from 2005-2020 from that record and output to the page

	$i = 2004;

	do {
		echo "data.addRow(['".$i."' ";
			$i++;
			while($row = mysql_fetch_assoc($prd2))
			{
			echo ",".$row[$i]." ";
			}
		echo "]);";
	} while ($i <= 2020);

The resulting javascript should look like this:

data.addRow(['2005', 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000]);

data.addRow(['2006', 10000, 5000, 7000, 28000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000, 12000, 8000, 9000, 25000]);

But the loop terminates after the first iteration.

 

Any ideas where my loop logic may have faultered here?

 

Thanks!


Viewing all articles
Browse latest Browse all 13200

Trending Articles