fetch user from database in ajax_chat-0.8.3 software

ajax_chat-0.8.3 software is free and you can download it form the site https://blueimp.net/ajax/ and install it. in this software you get 4 users which is static and if you need dynamic users and fetch that users from the database then you need to do some setting in the code provided by the ajax_chat module.

i will help you to fetch dynamic users in the chat module, once you did this then all your registered user can login in this module and chat with each other.

if you look in the installed directory then there is lib/data/users.php file, if you open this then you get below code

 
<?php
/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) Sebastian Tschan
 * @license GNU Affero General Public License
 * @link https://blueimp.net/ajax/
 */
 
// List containing the registered chat users:
$users = array();
 
// Default guest user (don't delete this one):
$users[0] = array();
$users[0]['userRole'] = AJAX_CHAT_GUEST;
$users[0]['userName'] = null;
$users[0]['password'] = null;
$users[0]['channels'] = array(0);
 
// Sample admin user:
$users[1] = array();
$users[1]['userRole'] = AJAX_CHAT_ADMIN;
$users[1]['userName'] = 'admin';
$users[1]['password'] = 'admin';
$users[1]['channels'] = array(0,1);
 
// Sample moderator user:
$users[2] = array();
$users[2]['userRole'] = AJAX_CHAT_MODERATOR;
$users[2]['userName'] = 'moderator';
$users[2]['password'] = 'moderator';
$users[2]['channels'] = array(0,1);
 
// Sample registered user:
$users[3] = array();
$users[3]['userRole'] = AJAX_CHAT_USER;
$users[3]['userName'] = 'user';
$users[3]['password'] = 'user';
$users[3]['channels'] = array(0,1);
?>

Replace this code with the below code but please do not forgot to set your table name and field names as per your database.

 
<?php
/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) Sebastian Tschan
 * @license GNU Affero General Public License
 * @link https://blueimp.net/ajax/
 */
 
// List containing the registered chat users:
$users = array();
 
$sql = "SELECT * FROM tbl_registered_user";
$result = $this->db->sqlQuery($sql);
if($result->numRows() > 0) {
 $condition = '';
 $i=0;
 while($row = $result->fetch()) 
 {	
	$users[$i] = array();
	$users[$i]['userRole'] = AJAX_CHAT_ADMIN;  // you can assign role as you want
	$users[$i]['userName'] = $row['username'];
	$users[$i]['password'] = $row['password'];
	$users[$i]['channels'] = array(0,1);;
	$i++;
 }
}
?>

same way you can change the channels as well, here channels means the chat room. please let me know if you need help to set the channels in ajax_chat module.