I am using the snippet code below to output the contents of a MySQL table as a simple list. It would be nice to add a ’View Detail’ link to output the rest of a record and perhaps to have the list output sortable/searchable.
Is there any way to do this?
Martin
<?php
$output = ’’;//create variable for holding the output
$sql = $modx->db->query( ’SELECT town, ass_name, email, website FROM `publicity` WHERE region="midlands" LIMIT 0, 1000’);//define the DB query, in this case the table is named ’tblprojects’, add WHERE AND etc. as needed
$resultArray = $modx->db->makeArray( $sql );//put it into an array
foreach($resultArray as $item)//go through each record in the array
{//start looping through the data array
$params[’region’]=$item[’region’];//set the placeholders, the $params sets the name of the placeholder, the $item is the column name from the DB table
$params[’town’]=$item[’town’];
$params[’ass_name’]=$item[’ass_name’];
$params[’email’]=$item[’email’];
$params[’website’]=$item[’website’];
$params[’phone’]=$item[’phone’];
$output.=$modx->parseChunk(’ProjectTpl’, $params, ’[+’, ’+]’);//define the chunk name and process the content, here it’s ProjectTpl which has the placeholders for the data
}//finish looping through the data array
return $output;//now return the output from the processed chunk
?>