• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access to the User_data -> username into my CI_SESSIONS database when I make a query

#1
[eluser]GonzaFY[/eluser]
THE SOLUTION IS AT THE END!


I am working in a function to get online users but I am having troubles making the query..

Code:
public function Estado($usuario)
  {
  
  
   // I get the last sessions and check if is my $usuario's sessions.
   $funcion = $this->CI->db->where('user_data', $usuario)
         ->where('last_activity >', time()-500)
         ->order_by('last_activity', 'desc')
         ->get('ci_sessions');  
  
   // If there is a result  
   if($funcion->num_rows() == 1)
   {
    
     // We return user's data
     return $funcion->row();
   }
    
  }

The problem is that I need check if the username stored in the user_data(serialized) is the same as the user that I am checking if is online.

If you don't understand me my user_data says:
Code:
a:7:{s:9:"user_data";s:0:"";s:2:"id";s:1:"1";s:7:"usuario";s:7:"gonzafy";s:6:"nombre";s:7:"Gonzalo";s:8:"apellido";s:16:"Fernandez";s:5:"rango";s:1:"2";s:8:"conexion";b:1;}

Then I need do:
Code:
// CHECK user_data[usuario] ..
$funcion = $this->CI->db->where('user_data[usuario]', $usuario)
         ->where('last_activity >', time()-500)
         ->order_by('last_activity', 'desc')
         ->get('ci_sessions');

Do you understand me?

I don't wanna use db->like('user_data', $usuario) because if two users have similar names like: Gonza and GonzaFY, when I am checking Gonza's connection I can get GonzaFY too so will cause troubles..

Thanks..


SOLUTION
I am so stupid... I only needed to request the last sessions and then check if those has userdata, if it has the user is connected so I only need get the username..

Code:
public function Todos()
  {
   $data = array();
   $consulta = $this->CI->db
       ->where('last_activity >', time()-300)
       ->order_by('last_activity', 'desc')
       ->get('ci_sessions');
      
   foreach($consulta->result() as $row)
   {
    $desencriptar = unserialize($row->user_data);
    if(isSet($desencriptar['usuario']))
    {
     $data[] = $row;
    
    
    }
    
    
   }
   return $data;  
  
  }

and then I call it (I am trying from my controller)

Code:
function conectados()
{
  
   $data = $this->miembros->Todos();
   if(!$data == '')
   {
    foreach($data as $result)
    {
     $columna = unserialize($result->user_data);
     echo $columna['usuario'] . '<br />';
    
    }
   }
   else {
    
    echo 'No hay ningun usuario online';
   }
  
  
}

#2
[eluser]LuckyFella73[/eluser]
post deleted .. irrelevant ...


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.