Page 1 of 1

RESOLVED Problem with while loops

Posted: Mon Dec 18, 2006 7:29 pm
by punchthemonkey94
Hello,

I'm trying to make a matrix builder in php. I have got it to work so that a user can specify how many rows and columns in the matrix, and then use that information in the next page to come up with a table, with inputs for each number place in the matrix.

The trouble I am having is showing the matrix that the user just input.

This is the code:

Code: Select all

<?php
	$rows = $_GET['rows'];
	$columns = $_GET['columns'];
	$i = 1;
	$j = 1;
	$n = 1;
	$k = 1;

	while ($k < ($rows + 1)) {
	echo "<tr>";
		while ($n < ($columns + 1)) {
			echo "<td>";
			echo $_POST['r'.$i.'c'.$j];
			$j++;
			$n++;
		}
	$n = 1;
	$i++;
	$k++;
	}
?>
The

Code: Select all

$_POST['r'.$i.'c'.$j];
seems to be where the problem occurs. It only displays the last row, last column's value, but since it's inside a loop, it should show all of them, in their own column and row in the table. Why is it only showing the last value?

If theres any more information you need from me, let me know.

Posted: Mon Dec 18, 2006 7:33 pm
by punchthemonkey94
I just looked at the page source, and I noticed this:

Code: Select all

<tr><td>2<td><td><tr><td><td><td><tr><td><td><td></table>
That means that did the loop correctly, but the variable "$_POST['r'.$i.'c'.$j];" is the problem. Can some one figure out why that variable doesnt work?

Posted: Mon Dec 18, 2006 7:36 pm
by punchthemonkey94
Sorry, I just realized the problem, it turned out to be an error in the previous page.