Skip to content

Commit

Permalink
#14 add filter and pick one drop down
Browse files Browse the repository at this point in the history
  • Loading branch information
Ths2-9Y-LqJt6 committed Mar 29, 2018
1 parent b21aca5 commit b4cc841
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ function __construct($host, $username, $password = '', $database, $table, $type
* @param array $rowsToFetchArray huh - i guess this is columns or fields to fetch - only fetch these
* @return array of results - will be an empty array if invalid params passed
*/
public function getRowsFromTable($table = null, $orderBy = null, $start = 0, $offset = 50, $rowsToFetchArray = array()){
public function getRowsFromTable($table = null, $orderBy = null, $start = 0, $offset = 50,
$rowsToFetchArray = array(), $filterKey = null, $filterValue = null){
if ($table == null){
$table = $this->table;
}
Expand All @@ -108,15 +109,25 @@ public function getRowsFromTable($table = null, $orderBy = null, $start = 0, $of
} else {
$rowsToFetch = '*';
}
if ($filterKey != null && $filterValue != null && $this->validateTableColumns(array($filterKey))){
$whereSql = ' WHERE ' . $filterKey . ' = :filterValue ';
$bindWhere = true;
} else {
$whereSql = '';
$bindWhere = false;
}
if ($orderBy != null && $this->validateTableColumns(array($orderBy))){
$orderBySql = " ORDER BY $orderBy ASC";
} else {
$orderBySql = " ";
}
$queryString = "SELECT $rowsToFetch FROM $table $orderBySql LIMIT :start, :offset";
$queryString = "SELECT $rowsToFetch FROM $table $whereSql $orderBySql LIMIT :start, :offset";
$query = $this->db->prepare($queryString);
$query->bindValue(':start', $start, PDO::PARAM_INT);
$query->bindValue(':offset', $offset, PDO::PARAM_INT);
if ($bindWhere){
$query->bindValue(':filterValue', $filterValue, PDO::PARAM_STR);
}
$query->execute();
return $query->fetchAll(PDO::FETCH_ASSOC);
}
Expand Down Expand Up @@ -447,6 +458,7 @@ class='form-control $primaryClass' maxlength='{$columnInfoArray['SIMPLE_SIZE']}'
$html .= "<select name='$colName' value='$value' id='$colName' class='form-control $primaryClass'
$requiredHtml $kvPairHtml>\n";
asort($columnInfoArray['SIMPLE_VALUES']);
$html .= "<option value='' class='empty-select'><em>Choose One</em></option>\n";
foreach ($columnInfoArray['SIMPLE_VALUES'] as $key => $option){
$selected = '';
if ($key == $value){
Expand Down Expand Up @@ -823,4 +835,4 @@ private function getNonceFormInput($nonce){
$name = $this->nonceKey ;
return "<input type='hidden' value='$nonce' name='$name' />\n";
}
}
}

0 comments on commit b4cc841

Please sign in to comment.