Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Output mySQL data in columns Jump to:  
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:
» 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 D...
» 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');
 
?>


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 63 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?