Basic Data Display - lokothodida/DM_Matrix GitHub Wiki
After you've built your table, added fields, configured their details and input data, you need to know how to actually display the data on your site. There are a number of ways to do so. You can stick the code into a component and display it through there; hard code it into the template or use plugin hooks to get the information displayed. These methods work on all of them.
The query method pulls an array of the existing data in the called table. The query that you perform is very similar to doing a (my)SQL query - saying SELECT fields FROM table ORDER BY field ASC/DESC etc....
<?php
// gets results
$results = $var->query("SELECT bar FROM foo ORDER BY id ASC");
?>
Loop through each entry and output what you want
<?php foreach ($results as $result) { ?>
<span><?php echo $result['bar']; ?></span>
<?php } ?>
You can use this process to output the field information as desired. The above example will output the data raw as it exists in the schema. To format the data (i.e. convert timestamps to date formats, parse BBCode etc...), run the query through the formatter before output, e.g.
<?php
// format results
$results = $var->formatQuery($results, 'foo');
?>
Some queries that you go through will require a break-up among pages. You have a client-side jQuery solution to this (pajinate) and a server side solution as well, for when the queries are large.
The best way to illustrate this is with a table example.
<script>
$(document).ready(function() {
$('.pajinate').pajinate();
});
</script>
<table class="pajinate">
<thead>
<tr>
<th>
<div class="page_navigation"></div>
</th>
</tr>
</thead>
<tbody class="content">
<?php foreach ($results as $result) { ?>
<tr>
<td>
<span><?php echo $result['bar']; ?></span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
// settings for the pagination
$key = 'page'; // key in the $_GET array for pagination
$max = 5; // maximum number of records per page
$range = 2; // number of links to show from the current page
$url = 'http://...'; // base URL for the paginated links
$delim = '&page=$1'; // URL structure for paginated link ($1 corresponds to the page number)
$results = $var->paginateQuery($results, $key, $max, $range, $url, $delim);
?>
The query is now an array that contains the results, paginated links and total number of results. To get a server-side version of the previous setup, use the following:
<table>
<thead>
<tr>
<th>
<div class="page_navigation"><?php echo $results['links']; ?></div>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($results['results'] as $result) { ?>
<tr>
<td>
<span><?php echo $result['bar']; ?></span>
</td>
</tr>
<?php } ?>
</tbody>
</table>