PHP Classes

File: class.crosstab.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Classes of  >  crosstab  >  class.crosstab.php  >  Download  
File: class.crosstab.php
Role: ???
Content type: text/plain
Description: classfile for crosstab
Class: crosstab
Mysql data in cross-tabular format.
Author: By
Last change:
Date: 12 years ago
Size: 2,823 bytes


Class file image Download


Class to display mysql data in cross-tabular format.
Made By member - tech team.
On April 20, 2002
Please go through the Readme.txt file provided with this pack.


// Please enter your hostname, username and password
// for mysql connection.


// Enter the database name in place of "<dbname>" below


// Class definition

class crosstab {

var $rowfield;
var $columnfield;
var $reffield;
var $crosstable;

// Constructor if u have username and password
function crosstab($row_field,$column_field,$ref_field,$cross_table){

function show()

	$sqlrow="SELECT  distinct $this->rowfield as ROW from $this->crosstable";
	$sqlcolumn="SELECT distinct $this->columnfield as COLUMN1 from $this->crosstable";
	$sqlelement="SELECT count($this->reffield) as CROSSVALUE,$this->rowfield,$this->columnfield from $this->crosstable group by $this->rowfield,$this->columnfield";
	$resrow=mysql_query($sqlrow) or die("could not select1 row");
	$rescolumn=mysql_query($sqlcolumn) or die("could not select2 column");
	$reselement=mysql_query($sqlelement) or die("could not select3 element");
	while($welement=mysql_fetch_array($reselement))	{
	echo "<font face=arial><table border=1><tr><td>Field</td>";
	for ($n=0;$n<=(count($column)-1);$n++){
		echo "<td>".$column[$n]."</td>";
	echo "</tr>";
	for ($m=0;$m<=(count($row)-1);$m++){
		echo "<tr>";
		for ($n=0;$n<=(count($column)-1);$n++){
			echo "<td>".$column[$n]."<td>";
				echo "<td>".$row[$m]."</td>";
			   	 	echo "<td>".$element[$row[$m]][$column[$n]]."</td>";
			  	 	$total[$n]=$total[$n] + $element[$row[$m]][$column[$n]];
		    			echo "<td>0</td>";
		echo "</tr>\n";
	echo "<td>Total</td>";
	for ($n=0;$n<=(count($column)-1);$n++){
		echo "<td><b><font size=-1>".$total[$n]."</font></b></td>";
	echo "</tr>";
	echo "</table>";
	echo " Total Records $ttotal";
// End of method	

// End of Class