Dynamo

Dynamo is a free PHP library that automatically draws basic HTML tables and forms based on the results of MySQL queries. It is open source, distributed under the GPL.

It is particularly useful for quickly and easily writing reports using mainly a MySQL query without writing a lot of PHP code.

The download includes a single PHP file that includes the Dynamo functions, an HTML quick reference guide, and a default CSS file for formatting the HTML results.

Example

Here is a quick example of the most common use of Dynamo to create an HTML table out of an SQL query.

<?php
 
	// Include the Dynamo Library
	include 'dynamo.php';
 
	// Setup the database
	$serv = 'localhost';
	$user = 'username';
	$pass = 'password';
	$base = 'database';
 
	// Make the connection and select the database
	mysql_connect($serv, $user, $pass);
	mysql_select_db($base);
 
	// Setup the query
	$query = "select id, first, last, password from member "
	       . "where password = 'password' limit 5";
 
	// Execute the query and generate an HTML table
	$table = DynamoTableQuery($query);
 
	// Display the table
	echo '<link rel="StyleSheet" href="dynamo.css" type="text/css">';
	echo $table;
 
?>

Screen Shot

And, here's a screen shot produced by the example above.

File Downloads

Replacements

If you don't want your query to be polluted with HTML code you can add a merge code to a column and then use a regular expression to replace that code with HTML later in your script. Here's an example.

// Setup the query
$query = "select id, first, last, concat('::', id, '::') as icons from member "
       . "where password = 'password' limit 5";
 
// Execute the query and generate an HTML table
$table = DynamoTableQuery($query);
 
// Setup the replacements for the icons column -- Uses regular expression back-reference ${1} 
$trash = '<a href="trash.php?id=${1}"><img src="images/trash.jpg"></a>';
 
// Replace the icons
$table = preg_replace('/::(.*)::/', $trash, $table);
 
// Display the table
echo '<link rel="StyleSheet" href="dynamo.css" type="text/css">';
echo $table;
comments powered by Disqus
dynamo.txt · Last modified: 2020/06/01 22:53 (external edit)