Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] como agregar codigo a existente

Estas en el tema de como agregar codigo a existente en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 18/08/2014, 21:05
 
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
  #2 (permalink)  
Antiguo 19/08/2014, 01:25
Avatar de NSD
NSD
Colaborador
 
Fecha de Ingreso: mayo-2012
Ubicación: Somewhere
Mensajes: 1.332
Antigüedad: 11 años, 11 meses
Puntos: 320
Respuesta: como agregar codigo a existente

mmm solo por curiosidad, ¿que dbal (el nombre de la clase) es? podrias poner el link para ver la clase completa por favor? con lo que mostraste alcanza para resolver el problema, pero me gusta mirar y analizar el funcionamiento de las clases de abstraccion

El problema podrias solucionarlo asi:
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.         ->where(array(
  9.             'id=' => 1
  10.         ))
  11.         ->get()
  12.         ->counter();
  13. }
__________________
Maratón de desafíos PHP Junio - Agosto 2015 en FDW | Reglamento - Desafios
  #3 (permalink)  
Antiguo 19/08/2014, 08:09
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: como agregar codigo a existente

gracias a todos ya logre hacerlo de esta manera

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

Etiquetas: existente, mysql, usuarios
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:49.