function getCount($params = array()) { global $database; $query = "SELECT COUNT(*) FROM " . $this->_tbl . " " . buildWhere($params); $database->setQuery($query); return intval($database->loadResult()); }
function loadByParams($params = array(), $limit = FALSE, $offset = FALSE) { global $database; $extra_clause = ""; if ($limit !== FALSE and !empty($limit)) { $extra_clause .= " LIMIT {$limit}"; } if ($offset !== FALSE and !empty($offset)) { $extra_clause .= " OFFSET {$offset}"; } $query = "SELECT " . $this->_tbl . ".id FROM " . $this->_tbl . " " . buildWhere($params) . " {$extra_clause};"; $database->setQuery($query); $database->query(); if ($database->getNumRows() > 1) { $jObjs = array(); $row = (array) $database->loadResultArray(); foreach ($row as $id) { $jObj = new jRemind($database); $jObj->load($id); array_push($jObjs, $jObj); } return $jObjs; } else { if ($database->getNumRows() == 1) { $this->load($database->loadResult()); return $this; } else { return FALSE; } } }
function getCount($params = array()) { global $database; // $where_clause = ""; // foreach ($params as $key => $val) { // if (is_array($val)) { // $where_clause .= "$key "; // switch ($val['type']) { // case 'in': // $where_clause .= "IN (" .$val['query']. ") AND "; // break; // case 'join': // break; // case 'left_join': // break; // } // } else { // $where_clause .= "$key = " .(is_numeric($val) ? $val : "'$val'"). " AND "; // } // } $where_clause = buildWhere($params); //substr($where_clause, 0, -5); $query = "SELECT COUNT(*) FROM " . $this->_tbl . " " . (strlen($where_clause) > 0 ? $where_clause : ""); jTipsLogger::_log('COMMENTS COUNT QUERY: ' . $query); $database->setQuery($query); return intval($database->loadResult()); }
public function merge($entity) { $table = getTable($entity); $data = getData($entity); $idColumn = key($data); $id = array_shift($data); $where = buildWhere($idColumn, $id); $update = $this->conn->update($table, $data); $return = $update->where($where, $id)->execute(); return $return; }
// Load data from the GET variables & return. loadData(&$readerhash, &$user_ident, &$username, &$format, &$purpose, &$types, &$types_avoid, &$page); $page_owner = $user_ident; // Run validation check. if fail, -1 is returned. if ($readerhash != '') { $reader_ident = folio_decodehash($readerhash); if ($reader_ident == -1) { error("Error, unable to validate your {$readerhash} value. Please log in and make sure you have the correct value."); } } elseif (isloggedin()) { $reader_ident = $_SESSION['userid']; } else { $reader_ident = -1; } // Build where condition $where = buildWhere($purpose, $reader_ident, $user_ident, $types, $types_avoid); // Get Data getData($where, $from, $page, &$results, &$resultcount); // Setup Metatags for RSS Discovery if (isloggedin()) { $metatags .= "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"" . url . $username . '/' . $purpose . '/rss/' . folio_createhash($_SESSION['userid']) . "\"/>"; } else { $metatags .= "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"" . url . $username . '/' . $purpose . "/rss/\"/>"; } // Print results to the screen. echo returnHTML($purpose, $format, $results, $resultcount, $page, $username); //////////////////////////////////////////////////// // Major Functions //////////////////////////////////////////////////// /** * Read in & validate information
//******************************************************EXTRACTION 1 $found_group = strrpos($query1, "group"); $found_where = strrpos($query1, "where"); $found_order = strrpos($query1, "order"); $target1 = buildTarget($query1); $from1 = buildFrom($found_where, $found_group, $found_order, $query1); $where1 = buildWhere($found_where, $found_group, $found_order, $query1); $group1 = buildGroup($found_group, $found_order, $query1); $order1 = buildOrder($found_order, $query1); //******************************************************EXTRACTION 2 $found_group = strrpos($query2, "group"); $found_where = strrpos($query2, "where"); $found_order = strrpos($query2, "order"); $target2 = buildTarget($query2); $from2 = buildFrom2($found_where, $found_group, $found_order, $query2); $where2 = buildWhere($found_where, $found_group, $found_order, $query2); $group2 = buildGroup($found_group, $found_order, $query2); $order2 = buildOrder($found_order, $query2); $query = buildQuery($cubetablenameB, $join_final, $target1, $target2, $from1, $from2, $where1, $where2, $group1, $group2, $order1, $order2); $result = exec_query($query); buildReport($result); //***************************************************************************************************************************************** function buildFrom($found_where, $found_group, $found_order, $query1) { //FROM if ($found_where == true) { $a = eregi("from (.+) where", $query1, $regs); } elseif ($found_group == true) { $a = eregi("from (.+) group", $query1, $regs); } elseif ($found_order == true) { $a = eregi("from (.+) order", $query1, $regs);
function getListadoDeProductos($filtros = null) { $where = buildWhere($filtros); if ($where) { $where .= " AND id_registro_estado=6"; } else { $where = "WHERE id_registro_estado=6"; } $sql = "SELECT * FROM view_productos\r\n\t\t\t\t{$where}\r\n ORDER BY producto"; $resultSet = getRS($sql); return $resultSet; }
function getCount($params = array(), $wrap = false) { global $database; $where_clause = ""; foreach ($params as $key => $val) { if (is_array($val)) { $where_clause .= "{$key} "; switch ($val['type']) { case 'in': $where_clause .= "IN (" . $val['query'] . ") AND "; break; case 'join': break; case 'left_join': break; } } else { $where_clause .= "{$key} = " . (is_numeric($val) ? $val : "'{$val}'") . " AND "; } } $where_clause = substr($where_clause, 0, -5); $query = "SELECT COUNT(*) FROM " . $this->_tbl . (strlen($where_clause) > 0 ? " WHERE {$where_clause}" : "") . ";"; if ($wrap == true) { $query = "SELECT " . $this->_tbl . ".id FROM " . $this->_tbl . " " . buildWhere($params); $query = "SELECT COUNT(*) FROM ({$query}) b"; } jTipsLogger::_log("Tip COUNT Query: {$query}"); $database->setQuery($query); return intval($database->loadResult()); }
} $i->query('SET group_concat_max_len = 3072'); $initial = substr($_GET['initial'], 0, 15); $sequence = substr($_GET['sequence'], 0, 50); $tagged = $_GET['tagged']; $begin = $_GET['begin']; $orderby = $_GET['orderby']; /* tagdate makes no sense if 'tags' is not selected */ if ($orderby == 'tagdate') { $tagged = 'tags'; } $rescount_sql = 'SELECT COUNT(*) AS rows ' . ' FROM resource r ' . ' WHERE ' . buildWhere($initial, $sequence, $tagged, $i); $i->query($rescount_sql); $total_results = $i->first_val('rows'); $fksql = "SELECT " . "r.id AS id, r.uri_raw AS url, \n" . "r.title AS title, r.visited AS visits, \n" . "r.added_timestamp AS added, \n" . "date_format(r.added_timestamp, '%e %M %Y à %T') as display_date, \n" . "(SELECT COUNT(resource_id) \n" . " FROM tagevent te \n" . " WHERE te.resource_id = r.id) \n" . "AS total_tagevs, \n" . "(SELECT \n" . " GROUP_CONCAT(DISTINCT tag.tagdisplay \n" . " ORDER BY tag.tagdisplay \n" . " SEPARATOR '\" \"') \n" . " FROM tagevent tee \n" . " JOIN tag ON tag.id = tee.tag_id \n" . " WHERE tee.resource_id = r.id \n" . " GROUP BY tee.resource_id) AS thesetags, \n" . "(select \n" . " group_concat(distinct e.ean13 \n" . " separator ', ') \n" . " from ean13 e \n" . " where e.resource_id = r.id) as theseeans, \n" . "(SELECT COUNT(*) FROM note n \n\t" . " WHERE n.resource_id = r.id) AS notecount, \n" . "(select \n" . " max(tagtime) \n\t" . " from tagevent te4 \n\t" . " where te4.resource_id = r.id) as last_tagged \n" . "FROM resource r \n" . "WHERE \n"; $fksql .= buildWhere($initial, $sequence, $tagged, $i); $fksql .= orderBySql($orderby); $fksql .= " LIMIT 50\n"; if (is_numeric($begin) && $begin >= 50) { $fksql .= " OFFSET {$begin}"; } print '<p><a href="#" id="showsql">Voir requête</a> (pour devel seulement)</p>' . '<div id="sql">' . '<p>' . str_replace("\n", '<br/>', $fksql) . '</p>' . '<p>' . str_replace("\n", '<br/>', $rescount_sql) . '</p>' . '</div>'; $i->query($fksql); if ($i->result_status == 'DBERR') { die($i->error_info()); } nextPrevious($begin, $i->result->num_rows, $total_results); $begin_with_current_results = $begin + $i->result->num_rows; $begin_display = $begin ? $begin : 1; print "<p>Reponses {$begin_display} à\n {$begin_with_current_results} sur {$total_results}. </p>"; print '<ul class="editresources">';