[eluser]Fribos[/eluser]
Hi, i'm codding a CI bassed Chat but i cant update online user's column using AJAX.
User's info comes from CI session class stored on ci_session table on my Database.
Usernames are stored in data_user column as a custom session data. I used serialize PHP method to capture that array and show usernames on a list.
Every 2.5 seconds the code refresh main container loading and reading a html file with chat log (time,username and text)
I want same refresh on online user's column, but now, i must call a method like get_all() and i have no idea how to do it.
fragment from my view
Code:
//Load the file containing the chat log
function loadLog(){
var oldscrollHeight = $("#chatbox2").attr("scrollHeight") - 20;
$.ajax({
url: "chat/log.html",
cache: false,
success: function(html){
$("#chatbox2").html(html); //Insert chat log into the #chatbox div
var newscrollHeight = $("#chatbox2").attr("scrollHeight") - 20;
if(newscrollHeight > oldscrollHeight){
$("#chatbox2").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
}
},
});
};
//Load the users online
function loadUsr(){
//document.getElementById('usuarios_chateando')[removed] = '/chatfinal/usuarios_online';
};
setInterval (loadLog, 2500); //Reload file every 2.5 seconds
setInterval (loadUsr, 2500); //Reload file every 2.5 seconds
...and this is my Chat_model (i need usuarios_online() to show users online)
Code:
class Chat_model extends Model {
function Chat_model()
{
parent::Model();
}
function cant_usuarios_online(){
$consulta = $this->db->query('SELECT * FROM ci_sessions WHERE user_data<>"" ');
return $consulta->num_rows();
}
function usuarios_online(){
$consulta = $this->db->query('SELECT * FROM ci_sessions WHERE user_data<>"" ');
//por cada registro muestro username y guardo la ip
foreach ($consulta->result_array() as $fila)
{
//Le doy formato de array a user_data
$usr = unserialize($fila['user_data']);
//guardo la IP del usuario en la variable $ip
$ip= $fila['session_id'];
//muestro el username
echo '<a href="chatfinal/whois/'.$ip.'" target="_blank">'.$usr['username'].'</a><br />';
}
}
function bannear($session_id){
//capturo datos dela sesion a bannear
$query = $this->db->query("SELECT ip_address FROM ci_sessions WHERE session_id='".$session_id."'");
if ($query->num_rows() > 0)
{
$row = $query->row();
$this->db->set('ip', $row->ip_address);
$this->db->insert('ci_ban');
}
}
}
I'll accept any idea, suggestion... everything is welcome
Thank and excuse my horrible english.