CoderZone.org

Category: >> PHP Code >> Print X Column Tables with PHP Bookmark and Share

<< lastnext >>

Snippet Name: Print X Column Tables with PHP

Description: An example of how to print tables with any number of columns using PHP. This example shows how the results of a mySQL query could be dynamically printed as a table 4 columns wide. The number of columns is set by the "$columns" variable.

Also see:
» Add a hidden field to a form dynam...
» Add more fields to a form dynamica...
» Javascript Include - allows dynami...
» Dynamically create HTML elements
» Dynamically add and remove elements
» Search and Replace On Every Field ...
» A JavaScript implementation of the...
» Converting Rows to Columns
» Output mySQL data in columns
» Dynamically Add/Remove rows in HTM...
» TABLE - Multiple Columns
» SELECT name columns
» INSERT: Multiple Column Table Or V...
» INSERT: Multiple Column Table Or V...
» List all indexed columns for a giv...
» Add random numbers to columns
» Get table with named columns
» Number Functions: Calculate ratio ...
» Quickly Optimize Database Tables (...

Comment: (none)

Author:
Language: PHP
Highlight Mode: PHP
Last Modified: January 09th, 2011

<?php
 
$columns = 4;
 
print "\n<table>";
$i = $columns;
 
while ($images = mysql_fetch_assoc($query_result)){
 
	if($i==$columns){ print "\n\t<tr>";}
 
		print "<td><img src='/image/$images [image_name]' /></td>\n";
 
		$i--;
 
		if($i == 0) {
		print "\n\t<tr>";
		$i = $columns;
	}
 
}
 
if($i != $columns){ print "\n\t\t<td colspan=\"$i\"></td>\n\t</tr>";}
 
echo "\n</table>";
 
?> 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 16