if (!isset($modx->myDB)) { $host = 'IPAdress'; $username = 'Username'; $password = 'Password'; $dbname = 'DBname'; $port = 3306; $charset = 'utf-8'; $dsn = "mysql:host=$host;dbname=$dbname;port=$port;charset=$charset"; $modx->myDB = new xPDO($dsn, $username, $password); echo $o = ($modx->myDB->connect()) ? 'Connected </br>' : 'Not Connected'; $path = MODX_CORE_PATH . 'components/nhs/'; if (!$modx->myDB->addPackage('packageName', $path . 'model/','')) { print 'There was a problem adding your package.'; }; }
if (isset($_POST['search'])) { $search = $_POST['search']; //$modx->getService('myclass','MyClass', MODX_CORE_PATH . '/components/myclass/model/myclass.class.php'); //$results = $modx->myclass->myDB->getCollection('LogData',array('diallednumber' => $search)); if ($results = $modx->myDB->getCollection('LogData', array('diallednumber' => $search))) { foreach ($results as $result) { $fields = $result->toArray(); $rows[] = $modx->getChunk('ShowData', $fields); } //$count['totalcount']= '<p>Total: ' . count($results) . '</p>'; //$modx->getChunk('searchCount',$count); echo $modx->myDB->getCount('LogData',$results); echo '<p>Total: ' . count($results) . '</p>'; $ph['rows'] = implode('',$rows); $output = $modx->getChunk('ShowDataOuter',$ph); } else { $output = $noresults; } } return $output;
<tr> <td>[[+callid]]</td> <td>[[+diallednumber]]</td> <td>[[+calldate]]</td> <td><button type="button" class="btn btn-danger">Delete</button></td> </tr>
<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>
<form method="post" action="[[~[[*id]]]]"> <input type="text" name='search' id='search' value="[[+search]]" /> <input type='submit' name='submit' id='submit' value='submit'/> </form>
] [[!dbconnect]] [[!dbform? &noresults='No items found.']] [[$SearchForm]] [
This question has been answered by Bruno17. See the first response.
<?php $limit = $modx->getOption('limit', $scriptProperties, '0'); $offset = $modx->getOption('offset', $scriptProperties, 0); $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total'); if (isset($_POST['search'])) { $search = $_POST['search']; //$modx->getService('myclass','MyClass', MODX_CORE_PATH . '/components/myclass/model/myclass.class.php'); //$results = $modx->myclass->myDB->getCollection('LogData',array('diallednumber' => $search)); //$count['totalcount']= '<p>Total: ' . count($results) . '</p>'; //$modx->getChunk('searchCount',$count); $c = $modx->myDB->newQuery('LogData'); $c->where(array('diallednumber' => $search)); $total = $modx->myDB->getCount('LogData', $c); echo '<p>Total: ' . $total . '</p>'; //set "total" placeholder for getPage $modx->setPlaceholder($totalVar, $total); //&limit, &offset if (!empty($limit)) { $c->limit($limit, $offset); } if ($results = $modx->myDB->getCollection('LogData', $c)) { 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;
[[!getPage? &elementClass=`modSnippet` &element=`getResources` &showHidden=`1` &tpl=`newsTpl` &limit=`3` &includeContent=`1` &includeTVs=`1` &processTVs=`1` &parents=`[[*id]]` &hideContainers=`1` &pageLimit=`5` &pageNavVar=`page.nav` ]] [[!+page.nav]]
[[!getPage? &element=`dbform` &limit=`5` &noresults=`No items found.` ]] [[!+page.nav]]
$limit = $modx->getOption('limit', $scriptProperties,0); $offset = $modx->getOption('offset', $scriptProperties,0); $totalVar = $modx->getOption('totalVar', $scriptProperties, 'total'); $output =''; if ((isset($_POST['search'])) || (isset($_SESSION['searchResult']))) { $search = $_POST['search']; if (isset($search)) {$_SESSION['searchResult'] = $search;}; echo '<p>Session search = ' . $_SESSION['searchResult'] . '</p>'; $c = $modx->myDB->newQuery('LogData'); $c->where(array('diallednumber' => $_SESSION['searchResult'])); $total = $modx->myDB->getCount('LogData', $c); echo '<p>Total records found: ' . $total . '</p>'; //set "total" placeholder for getPage $modx->setPlaceholder($totalVar, $total); //&limit, &offset if (!empty($limit)) { $c->limit($limit, $offset); } //run query and loop through the results if ($results = $modx->myDB->getCollection('LogData', $c)) { 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;