Quick Search:
 
 PHP Code: Output mySQL data in columns Jump to:  
Category: >> PHP Code >> Output mySQL data in columns  

<< 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:
» Format money as millions, billions, et...
» Make alternating color table rows auto...
» Search and Replace On Every Field In E...
» Convert UK Dates To mySQL Format Dates
» Calculate the difference between two t...
» Highlight table rows on rollover
» Converting Rows to Columns
» Dynamically Add/Remove rows in HTML ta...
» LOCKS: Table Locking
» TABLESPACE: Show contiguous space
» TABLESPACE: SYSAUX tablespace
» TABLESPACE: Tablespace management
» TABLESPACE: List tablespaces, files, ...
» TABLESPACE: Dropping Tablespaces
» TABLESPACE: Alter Permanent Tablespace
» TABLESPACE: Transportable tablespaces
» TABLESPACE: Tempfile operations
» TABLESPACE: Create temp tablespace
» TABLESPACE: Change UNDO tablespace
» TABLESPACE: Undo Tablespace
» TABLESPACE: SYSAUX Tablespace
» TABLESPACE: Set default tablespace type
» TABLESPACE: Oracle Managed Auto-extend...
» TABLESPACE: Permanent Tablespace Using...
» TABLE: Constraints
» TABLE: Options
» TABLE: Using Select Statement With Data
» TABLE:  Multiple Columns
» TABLE:  queries
» TABLE: simple heap table

Comment: (none)

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');
 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org