#native_company# #native_desc#
#native_cta#

PHPdbView

By Tudor Oprea
on November 23, 2000

Version: 0.2

Type: Full Script

Category: Databases

License: GNU General Public License

Description: Outputs the contents of an entire database in HTML tables. Take care not to use it for huge databases.

<?php
//
// PHPdbView 0.2 : 02-06-2000
// Written by Tudor Oprea ([email protected])
// Shows contents of a database in HTML.
// To show another database, change $dbname
//  
//
 
?>


<?php
		
	$dbname = "test";
	$loginname = "test";
	$loginpass = "test";
	$dbhost = "localhost";
	
	echo('<html><body bgcolor="#FFFFFF">');
	echo('<font face="arial" size="+4"><center>');
	echo("Database $dbname");
	
	$id_link = @mysql_connect($dbhost, $loginname, $loginpass);
	
	$tables = mysql_list_tables($dbname, $id_link);
	
	$num_tables = mysql_num_rows($tables);

	// store table names in an array
	$arr_tablenames[] = '';
	
	// store number of fields per table(index 0,1,2..) in an array
	$arr_num_fields[] = '';
	for ($i=0; $i < $num_tables; $i++) {
		$arr_tablenames[$i] = mysql_tablename($tables, $i);
		$arr_num_fields[$i] = mysql_num_fields(mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link));
	}
	
	// store field names in a multidimensional array:
	// [i] == table number, [ii] == field number for that table
	for ($i=0; $i < $num_tables; $i++) {
		for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
			$result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
			$hash_field_names[$i][$ii] = mysql_field_name($result, $ii);
		}	
	}
	
	for ($i=0; $i < $num_tables; $i++) {
		echo("<center><h2>Table $arr_tablenames[$i] </h2></center>");
		echo('<table align="center" border="2"  cellpadding="2" cellspacing="0"><tr>');
		$result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
		for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
			echo("<th>");
			echo $hash_field_names[$i][$ii];
			echo("</th>");
		}
		echo("</tr><tr>");
		$number_of_rows = @mysql_num_rows($result);
		for ($iii = 0; $iii < $number_of_rows; $iii++) {
			$record = @mysql_fetch_row($result);
			for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
				echo("<td>");
				echo $record[$ii];
				echo("</td>");
			}
		echo("</tr>");
		}
		echo("</table>");
	}
	


	echo('</body></html>');
?>