PHP DataGridView 0.1

Page 1 of 1

0 Replies - 338 Views - Last Post: 08 August 2009 - 09:13 PM

#1 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

PHP DataGridView 0.1

Posted 08 August 2009 - 09:13 PM

Description: just change then hostname, username, password, databaseName, tablename and change your query (if you want).
<?PHP
/*
	Data Grid View Version 0.1 in PHP By Noorahmad for DIC (http://www.dreamincode.net)
	Date: 8-8-2009
*/
?>
<style type="text/css">
<!--
.header {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: bold;
	color: #000000;
	background-color: #FF9900;
	text-align: center;
}
.rows {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	font-weight: normal;
	color: #000000;
	background-color: #CCCCCC;
}
-->
</style>
<?php
function dgv_php_v1($host='localhost',$user='root',$pass='',$db='abadb',$tbl='users'){

	$con = mysql_connect($host,$user,$pass)or die(mysql_error());
	if(!$con){
		die("Connection error");
	}
	mysql_select_db($db);
	$cols = mysql_query("show columns from $tbl")or die(mysql_error());
	$cols_array = array();
	$cols_num  = mysql_num_rows($cols);
	echo "<table width=100% border=0 cellpadding=1 cellspacing=2><tr class='header'>";
		while($fetch_cols = mysql_fetch_assoc($cols)){	
			echo "    <td>$fetch_cols[Field]</td>";
			$cols_array[] .=$fetch_cols['Field'];
		}
	echo "</tr>";
	
	$query_str = "SELECT * FROM $tbl";
	$query = mysql_query($query_str)or die(mysql_error());
			
	while($query_fetch = mysql_fetch_assoc($query)){
	echo "<tr class='rows'>";
		for($i=0;$i<(count($cols_array));$i++){
			echo "<td>".$query_fetch[$cols_array[$i]]."</td>";
		}
	echo "</tr>";
	}
	echo "</table>";
}
$host='localhost';
$user='root';
$pass='';
$db='dbname';
$tbl='tblname';
dgv_php_v1($host,$user,$pass,$db,$tbl);
?>


Is This A Good Question/Topic? 0
  • +

Page 1 of 1