[ create a new paste ] login | about

Link: http://codepad.org/WlrZaz7R    [ raw code | output | fork ]

PHP, pasted on Aug 21:
<?php
$columns = 4;		// The number of columns you want.

echo "<table>";		// Open the table

// Main printing loop. change `30` to however many pieces of data you have
for($i = 0; $i < 30; $i++)
{
	// If we've reached the end of a row, close it and start another
	if(!($i % $columns))
	{
		if($i > 0)
		{
			echo "</tr>";		// Close the row above this if it's not the first row
		}
		
		echo "<tr>";	// Start a new row
	}
	
	echo "<td>Cell</td>";		// Add a cell and your content
}

// Close the last row, and the table
echo "</tr>
</table>";
?>


Output:
1
2
<table><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td><td>Cell</td><td>Cell</td></tr><tr><td>Cell</td><td>Cell</td></tr>
</table>


Create a new paste based on this one


Comments: