This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
dynamo [2011/04/25 17:28] Joel Dare |
dynamo [2020/06/01 22:53] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== 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. | ||
| + | |||
| + | <code php> | ||
| + | <?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; | ||
| + | |||
| + | ?> | ||
| + | </code> | ||
| + | |||
| + | ===== Screen Shot ===== | ||
| + | |||
| + | And, here's a screen shot produced by the example above. | ||
| + | |||
| + | {{ dynamo_table.gif }} | ||
| + | |||
| + | ===== File Downloads ===== | ||
| + | |||
| + | [[http://www.joeldare.com/dynamo/files/dynamo.html|Dynamo Quick Reference Guide]] | ||
| + | |||
| + | [[http://www.joeldare.com/dynamo/files/dynamo.zip|Download Dynamo 2011-04-25 (Zip File)]] | ||
| + | |||
| + | ===== 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. | ||
| + | |||
| + | <code php> | ||
| + | // 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; | ||
| + | |||
| + | </code> | ||