Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Query builder for getting most datatables
- *
- * @param string $table
- * @param string|array $fields
- * @param array $where
- * @param string $distinct_field
- * @param string $order
- * @param string $limit
- * @internal param bool $distinct
- * @internal param null|string $field
- * @return array $roles_array with rows from database
- */
- function getDataTables($table, $fields = '*', $where = array(), $distinct_field = null, $order = null, $limit = null){
- $where_sql = '';
- if(count($where) > 0)
- {
- foreach($where as $column => $value)
- {
- $where_sql .= "`". datacheck($column) ."` = '". datacheck($value) ."' AND ";
- }
- }
- $where_sql .= " 1=1";
- $db = new db('default');
- if(!is_null($distinct_field))
- $select = "SELECT DISTINCT `".datacheck($distinct_field)."`";
- else
- {
- if(count($fields) > 0 && is_array($fields))
- {
- $select = "SELECT ";
- $total = count($fields);
- $i = 1;
- foreach($fields as $field){
- $select .= '`'.$field.'`';
- if($total != $i)
- {
- $select .= ', ';
- $i++;
- }else{
- $select .= " ";
- $i = 0;
- }
- }
- }elseif($fields != '*'){
- $select = "SELECT `".$fields."` ";
- }
- else{
- $select = "SELECT * ";
- }
- }
- $sql = $select ."FROM `".$table."` WHERE ".$where_sql;
- if(!is_null($order))
- $sql .= " ORDER BY `". datacheck($order) ."` ";
- if(!is_null($limit))
- $sql .= " LIMIT ".datacheck($limit);
- $datatable = $this->query($sql);
- $rows_array = array();
- while($row = $datatable->fetchrow())
- {
- array_push($rows_array, $row);
- }
- return $rows_array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement