Loop Demo
PHP Code Examples
[Download]
<?php $title = 'Looping On A Query String'; include '../head1.inc'; 
// This page expects to have ?NNNxMMM appended to its URL.  That is
// the query string which it uses to do its work.
//
// The code here simply generates an array of blue dots of the
// indicate size, rows x columns.
$size = $_SERVER["QUERY_STRING"];
if(!$size) {
	echo "You did not specify a matrix size.";
} else if (!preg_match("/^[0-9]+x[0-9]+$/", $size)) {
	echo "Your size specification of $size was not ",
		"Well-formed.";
} else {
	// Split the string up into the two numbers.  Note that the resulting 
	// strings of digits can be treated directly as numbers.
	list($rows, $cols) = explode('x', $size);

	print "Here is the $rows-row x $cols-column table of dots you ";
	print "requested.<p><table>\n";
	for($r = 1; $r <= $rows; ++$r) {
		print "<tr>";
		for($c = 1; $c <= $cols; ++$c)
			echo "<td><img src=\"/~bennet/icons/bluedot.gif\">",
				"</td>";
		print "</tr>\n";
	}
	print "</table>";
}
?>
</body>
</html>