Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/08/2014, 21:05
xoceunder
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
como agregar codigo a existente

ok es que ando implementando y modificando un script donde quiero poder hacer una consulta como ejemplo

esta esto y es para buscar todo los usuarios online

Código PHP:
Ver original
  1. function get_offline_users(){
  2.     return Mysql::getInstance()
  3.         ->from('users')
  4.         ->count()
  5.         ->where(array(
  6.             'UNIX_TIMESTAMP(keep_alive)<=' => 'UNIX_TIMESTAMP(now())-'.Config::get('watchdog_timeout')*2
  7.         ))
  8.         ->get()
  9.         ->counter();
  10. }

pues quiero que en vez de que busque todo los usuarios solo busque los usuarios que creo el que este iniciado la secion

quiero agregar esto WHERE id=1 a la function get_offline_users()

y esta es la funcion where

Código PHP:
Ver original
  1. public function where($key, $type = 'AND ', $value = null, $quote = true) {
  2.  
  3.         if (empty($key)) {
  4.             return $this;
  5.         }
  6.  
  7.         if (!is_array($key)) {
  8.             $keys = array($key => $value);
  9.         } else {
  10.             $keys = $key;
  11.         }
  12.  
  13.         $where = array();
  14.  
  15.         foreach ($keys as $key => $value) {
  16.  
  17.             //$prefix = (count($this->where) == 0) ? '' : $type;
  18.             $prefix = (count($where) == 0) ? '' : $type;
  19.  
  20.             if ($quote === -1) {
  21.                 $value = '';
  22.             } else {
  23.  
  24.                 if ($value === null) {
  25.                     if (!$this->has_operator($key)) {
  26.                         $key .= ' IS';
  27.                     }
  28.  
  29.                     $value = ' NULL';
  30.                 } else {
  31.                     if (!$this->has_operator($key) && !empty($key)) {
  32.                         $key = $key . '=';
  33.                     } else {
  34.                         preg_match('/^(.+?)([<>!=]+|\bIS(?:\s+NULL))\s*$/i', $key, $matches);
  35.                         if (isset($matches[1]) && isset($matches[2])) {
  36.                             $key = trim($matches[1]) . '' . trim($matches[2]);
  37.                         }
  38.                     }
  39.  
  40.                     $value = $this->escape($value);
  41.                 }
  42.             }
  43.  
  44.             //$this->where[] = $prefix.$key.$value;
  45.  
  46.  
  47.             /*if (empty($where)){
  48.                 $where .= ' AND ('.$prefix.$key.$value.'';
  49.             }*/
  50.  
  51.             $where[] = $prefix . $key . $value;
  52.         }
  53.  
  54.         $where_str = '(' . implode(' ', $where) . ')';
  55.  
  56.  
  57.         if (count($this->where) != 0) {
  58.             //$where = "AND '('.$where.')";
  59.  
  60.             $where_str = ' AND ' . $where_str;
  61.  
  62.         }
  63.  
  64.         /*$this->where[] = '('.$where.')';*/
  65.         $this->where[] = $where_str;
  66.  
  67.         return $this;
  68.     }

Última edición por xoceunder; 18/08/2014 a las 21:42