Location: PHPKode > scripts > Easy Data Grid > easy-data-grid/datagrid.class.php
<?php
// Programmed by Reza Salehi - hide@address.com - Free for non-commercial use. , Nov 2005
class dataGrid
{
	var $dataSource;
	var $dataKeyField;
	var $nextPage;
	var $nextPageLable;
	var $colNum;
	var $fieldsToShow;
	var $rowColor;	
	var $width;
	//
	function dataGrid($dataSource, $dataKeyField, $fieldsToShow, $nextPage, $nextPageLable, $rowColor, $width)
	{
		$this->dataSource=$dataSource;
		$this->dataKeyFeild=$dataKeyField;
		$this->nextPage=$nextPage;
		$this->nextPageLable=$nextPageLable;
		$this->fieldsToShow=$fieldsToShow;
		$this->colNum=sizeof($this->fieldsToShow);
		$this->rowColor=$rowColor;
		$this->width=$width;
	}
	//
	function create()
	{
		$rowColor=false;
		print("<table cellpadding=0 cellspacing=0 width=$this->width border=0>");		
		print("<tr>");
		for($i=0; $i<$this->colNum; $i++)
		{
			print("<td>");
			print($this->fieldsToShow[$i]);
			print("</td>");
		}
		//
		if($this->nextPage!=NULL) print("<td>".$this->nextPageLable."</td>");
		//
		print("</tr>");
		//
		while($row=mysql_fetch_array($this->dataSource))
		{
			$rowColor=!$rowColor;
			if($rowColor)
				print("<tr bgcolor=".$this->rowColor.">");
			else
				print("<tr>");
			for($i=0; $i<$this->colNum; $i++)
			{
				print("<td>");
				print($row[$this->fieldsToShow[$i]]);
				print("</td>");
			}
			//
			if($this->nextPage!=NULL) print("<td><a href=".$this->nextPage."?".$this->dataKeyFeild."=".$row[$this->dataKeyFeild]
			." target=blank>".$this->nextPageLable."</a></td>");
			//
			print("</tr>");
		}
		print("</table>");
	}
}
//

?>
Return current item: Easy Data Grid