CoderZone.org

Category: >> PHP Code >> Output mySQL data in columns Bookmark and Share

<< lastnext >>

Snippet Name: Output mySQL data in columns

Description: A simple PHP script that outputs data into formatted columns.

This script takes a mySQL array and displays it in a table with a user-customizable number of columns. Simply change the "$cols" variable to alter the number of columns.

Also see:
» Print X Column Tables with PHP
» Get database and table sizes
» Simple directory viewer / browser
» Recursive Directory Browser
» Select text in a DIV, SPAN, or tab...
» Get Table Row Data On Click
» Format money as millions, billions...
» Make alternating color table rows ...
» Search and Replace On Every Field ...
» Convert UK Dates To mySQL Format D...
» Calculate the difference between t...
» Highlight table rows on rollover
» Converting Rows to Columns
» Dynamically Add/Remove rows in HTM...
» LOCKS: Table Locking
» TABLESPACE: Show contiguous space
» TABLESPACE: SYSAUX tablespace
» TABLESPACE: Tablespace management
» TABLESPACE: List tablespaces, fil...
» TABLESPACE: Dropping Tablespaces
» TABLESPACE: Alter Permanent Tables...
» TABLESPACE: Transportable tablespa...
» TABLESPACE: Tempfile operations
» TABLESPACE: Create temp tablespace
» TABLESPACE: Change UNDO tablespace
» TABLESPACE: Undo Tablespace
» TABLESPACE: SYSAUX Tablespace
» TABLESPACE: Set default tablespace...
» TABLESPACE: Oracle Managed Auto-ex...
» TABLESPACE: Permanent Tablespace U...

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: April 03rd, 2010

<?php
 
// show data from a mysql query in columns
// change the query below as needed, and the 
// "$cols" variable to set the number of columns
 
$the_query = "SELECT * FROM mytable";
 
$result = mysql_query($the_query);
 
$rows = mysql_num_rows($result);
$rcounter = 1;
$cols = 2;
print ('<table>\n');
 
	for($i = 0; $i < $rows / $cols; $i++) {
	print ('<tr>');
		for($j=0; $j < $cols && $rcounter <= $rows ;$j++, $rcounter++) {
		print ("<td>(data to be displayed goes here)</td>\n");
		}
	print ('</tr>\n');
	}
 
print ('</table>\n');
 
?>
 
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: 22