if (isset($_POST['search'])) {
$search = $_POST['search'];
$results = $modx->myDB->getCollection('LogData',array('diallednumber' => $search));
if ($results) {
$output .= '<table class="table table-striped">';
$output .= '<thead>';
$output .= '<tr>';
$output .= '<th>Call Id:</th>';
$output .= '<th>Dialled Number:</th>';
$output .= '<th>Call Date</th>';
$output .= '<th>Delete</th>';
$output .= '</tr>';
$output .= '</thead>';
$output .= '<tbody>';
foreach($results as $result) {
$fields = $result->toArray();
$output .= $modx->getChunk('ShowData', $fields);
}
$output .= '</tbody>';
$output .= '</table>';
}else {
return 'No items found.';
}
}
return $output;
<table class="table table-striped"> <thead> <tr> <th>Call Id:</th> <th>Dialled Number:</th> <th>Call Date</th> <th>Delete</th> </tr> </thead> <tbody>
</tbody> </table>
This question has been answered by Bruno17. See the first response.
<?php
if (isset($_POST['search'])) {
$search = $_POST['search'];
if ($results = $modx->myDB->getCollection('LogData', array('diallednumber' => $search))) {
foreach ($results as $result) {
$fields = $result->toArray();
$rows[] = $modx->getChunk('ShowData', $fields);
}
$ph['rows'] = implode('',$rows);
$output = $modx->getChunk('ShowDataOuter',$ph);
} else {
$output = $noresults;
}
}
return $output;
<table class="table table-striped"> <thead> <tr> <th>Call Id:</th> <th>Dialled Number:</th> <th>Call Date</th> <th>Delete</th> </tr> </thead> <tbody> [[+rows]] </tbody> </table>
[[yoursnippet? &noresults=`No items found.`]]