RESOLVED Problem with while loops

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
punchthemonkey94
Forum Newbie
Posts: 6
Joined: Mon May 29, 2006 1:22 am

RESOLVED Problem with while loops

Post 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.
Last edited by punchthemonkey94 on Mon Dec 18, 2006 7:35 pm, edited 1 time in total.
punchthemonkey94
Forum Newbie
Posts: 6
Joined: Mon May 29, 2006 1:22 am

Post 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?
punchthemonkey94
Forum Newbie
Posts: 6
Joined: Mon May 29, 2006 1:22 am

Post by punchthemonkey94 »

Sorry, I just realized the problem, it turned out to be an error in the previous page.
Post Reply