PHP Classes

File: class.crosstab.php

Recommend this page to a friend!
  Classes of naukri.com   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: 22 years ago
Size: 2,823 bytes
 

Contents

Class file image Download
<?php /******************************************************* Class to display mysql data in cross-tabular format. Made By member - http://www.naukri.com 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. $db=mysql_connect("<hostname>","<username>","<password>"); // Enter the database name in place of "<dbname>" below mysql_select_db("test",$db); // 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){ $this->rowfield=$row_field; $this->columnfield=$column_field; $this->reffield=$ref_field; $this->crosstable=$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"); @mysql_close($db); $i=0; while($wrow=mysql_fetch_array($resrow)){ $row[$i]=$wrow[ROW]; $i++; } $i=0; while($wcolumn=mysql_fetch_array($rescolumn)){ $column[$i]=$wcolumn[COLUMN1]; $i++; } while($welement=mysql_fetch_array($reselement)) { $element[$welement[$this->rowfield]][$welement[$this->columnfield]]=$welement[CROSSVALUE]; } 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>"; if($n==0) echo "<td>".$row[$m]."</td>"; if($element[$row[$m]][$column[$n]]){ echo "<td>".$element[$row[$m]][$column[$n]]."</td>"; $total[$n]=$total[$n] + $element[$row[$m]][$column[$n]]; $ttotal=$ttotal+$element[$row[$m]][$column[$n]]; } else 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 } ?>