Дайте ссылку на класс который бы сам формировал таблицы из SQL запросов, этот бы подошел
http://www.phpclasses.org/browse/package/2052.html но phpclasses.org как обычно в дауне...
Добавлено: Сорри, нашел сам.
Код: class swemc
{
var $aResult = array();
var $iConnID;
var $strHost;
var $strUser;
var $strPass;
var $strDb;
var $iFields;
var $iRecs;
var $aFieldNames = array();
var $aTdwidth = array();
var $bDebug = FALSE;
function swemc ()
{
define ("MYSQLHOST","localhost");
define ("MYSQLUSER","root");
define ("MYSQLPASS","");
define ("MYSQLDB","reloader");
$this->strHost = MYSQLHOST;
$this->strUser = MYSQLUSER;
$this->strPass = MYSQLPASS;
$this->strDb = MYSQLDB;
$this->iFields = 0;
$this->iRecs = 0;
$this->bDebug = FALSE;
return ($this->connect()) ;
}
function connect()
{
$this->iConnID=@mysql_connect($this->strHost, $this->strUser, $this->strPass);
if ($this->iConnID)
{
if (@mysql_select_db($this->db))
return $this->iConnID;
else
{
if ($this->bDebug == TRUE)
$this->printerror();
return FALSE;
}
}
else
{
if ($this->bDebug == TRUE)
$this->printerror();
return FALSE;
}
}
function disconnect()
{
$this->free_result();
if ( @MYSQL_CLOSE($this->iConnID))
$this->iConnID = FALSE;
}
function query($querystring)
{
if (!$this->iConnID)
die("No connection to mySql<br>");
$this->aResult = mysql_db_query($this->strDb,$querystring,$this->iConnID);
if ( !$this->aResult)
{
if ($this->bDebug == TRUE)
$this->printerror(1); // print the errmsg and exit
}
if ( eregi("select",$querystring))
{
$this->iRecs = @mysql_num_rows($this->aResult);
$this->iFields = @mysql_num_fields($this->aResult);
// get the field-names
for($x=0;$x<$this->iFields;$x++)
{
$this->aFieldNames[$x] = @mysql_field_name($this->aResult,$x);
}
return $this->iRecs;
}
elseif ( eregi("insert",$querystring))
{
return mysql_insert_id($this->iConnID);
}
else
{
return ( mysql_affected_rows($this->iConnID));
}
}
function td_width($width_array)
{
$x = count($width_array);
if ($x != $this->iFields)
{
if ($this->bDebug)
{
echo "incorrect number in width-array<br>";
echo " $x in array, $this->iFields in record";
}
return;
}
for ($i = 0; $i < $x; $i++)
$this->aTdwidth[$i] = $width_array[$i];
}
function tab_out($with_table_head,$css_class="noCSS" )
{
if (count($this->aTdwidth)) // are there width-values ?
$bWidth = TRUE;
else
$bWidth = FALSE;
echo "<table border='1'";
if ($css_class != "noCSS")
echo "class=\"$css_class\" ";
echo ">";
if ( $with_table_head == TRUE )
{
echo "<tr class=\"$css_class\">";
for ($i=0;$i<$this->iFields;$i++)
{
if ($bWidth == TRUE)
$width = $this->aTdwidth[$i];
else
$width = 100/$this->iFields."%";
echo "<th class=\"$css_class\" width=\"$width\">";
echo ucfirst($this->aFieldNames[$i]);
echo "</th>";
}
echo "</tr>";
}
for ($j = 0; $j < $this->iRecs; $j++)
{
echo "<tr class=\"$css_class\">";
for ($k=0;$k<$this->iFields;$k++)
{
if ($bWidth == TRUE)
$width = $this->aTdwidth[$k];
else
$width = 100/$this->iFields."%";
echo "<td width=\"$width\" class=\"$css_class\">";
$xtmp = mysql_result($this->aResult,$j,$k);
if (strlen($xtmp))
echo $xtmp;
else
echo" ";
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
}
function tb_tab_out($css_class="standard", $width="80%")
{
if (count($this->aTdwidth))
$arr_breiten = TRUE;
echo "<p class=\"center\"><table class=\"$css_class\" width='$width' align='center'>";
echo "<tr>";
for ($i=0;$i<$this->iFields;$i++)
{
if ($arr_breiten)
$width = $this->aTdwidth[$i];
else
$width = 100/$this->iFields."%";
echo "<th width=\"".$width."\">";
echo strtoupper($this->aFieldNames[$i]);
echo "</th>";
}
echo "</tr>";
for ($j = 0; $j < $this->iRecs; $j++)
{
echo "<tr>";
$l=0;
for ($k=0;$k<$this->iFields-1;$k++)
{
if ($arr_breiten)
$width = $this->aTdwidth[$k];
else
$width = 100/$this->iFields."%";
echo "<td width=\"".$width."\">";
$xtmp = mysql_result($this->aResult,$j,$k);
if (strlen($xtmp))
echo $xtmp;
else
echo" ";
echo "</td>";
$l=$k+1;
}
if ($arr_breiten)
$width = $this->aTdwidth[$k];
else
$width = 100/$this->iFields."%";
echo "<td width=\"".$width."\">";
$xtmp = mysql_result($this->aResult,$j,$l);
$param = "detail";
$paramwert = $xtmp;
$act_url = "detail.php";
if (strlen($xtmp))
echo postButton("Ansehen",$act_url,$param,$paramwert);
else
echo" ";
echo "</td>";
echo "</tr>";
}
echo "</table></p>";
}
function fetch_field($recno,$fieldno_or_fieldname)
{
return mysql_result($this->aResult,$recno,$fieldno_or_fieldname);
}
function fetch_record($recno,$arr_type = MYSQL_BOTH)
{
if (!@mysql_data_seek($this->aResult,$recno))
{
if ($this->bDebug == TRUE)
$this->printerror(TRUE);
}
$arr = mysql_fetch_array($this->aResult,$arr_type);
return $arr;
}
function single_out($recno,$cssClass="noCSS" )
{
echo "<table border=\"1\"";
if ($cssClass != "noCSS")
echo " class=\"$cssClass\"";
echo ">";
for ($i=0; $i < $this->iFields; $i++)
{
echo "<tr>";
echo "<td class=\"".$tableclass."\">";
echo strtoupper($this->aFieldNames[$i]);
echo "</td>";
echo "<td class=\"".$tableclass."\">";
$xtmp = mysql_result($this->aResult,$recno,$i);
if (strlen($xtmp))
echo $xtmp;
else
echo" ";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
function free_result()
{
if($this->aResult)
{
@mysql_free_result($this->aResult);
$this->iRecs = $this->iFields = 0;
}
}
function printerror($exitnow = "FALSE")
{
echo "mySQL-Error No: " . mysql_errno()." - " .mysql_error();
if ($exitnow)
exit;
}
}