Skip to content

Instantly share code, notes, and snippets.

@Ammly
Created June 14, 2016 14:57
Show Gist options
  • Save Ammly/be68862b1884c19281715ce25348245d to your computer and use it in GitHub Desktop.
Save Ammly/be68862b1884c19281715ce25348245d to your computer and use it in GitHub Desktop.
Reload list items every 30 seconds. The php functions are getting the users from mysql db (working correctly)
<?php
<div class="usr_content">
<ul>
// list item to reload
<li class="disabled success" id="reload">Online Users
<?php
$onlineUsers = $demo->getOnlineUsers($current_user, $user_company);
foreach ($onlineUsers as $key => $onlineUser) {
if (is_array($onlineUser)){
$cls = $key == 0 ? 'selected' : '';
?>
<ul id="users">
<li id="<?= $onlineUser['id']?>" >
<label><?= $onlineUser['username'] ?>
<img src="assets/images/bullet_green.png" alt="onlines">
<small>online</small></label>
</li>
</ul>
<?php
}
}
?>
</li>
//
<li > All Users
<?php
$users = $demo->getAlliUsers($user_company);
foreach ($users as $key => $user) {
if (is_array($user)){
$cls = $key == 0 ? 'selected' : '';
?>
<ul id="users">
<li id="<?= $user['id']?>" >
<label><?= $user['username'] ?></label>
<img src="assets/images/bullet_yellow.png" alt="onlines">
<small>offline</small></label>
</li>
</ul>
<?php
}
}
?>
</li>
</ul>
</div>
<script>
//reload #users every 30 sec
var $online_users = $("#reload");
setInterval(function () {
$online_users.load("index.php #reload");
}, 30000);
</script>
@lestoni
Copy link

lestoni commented Jun 14, 2016

does the whole page reload or is it just a component in the page that reloads?

@lestoni
Copy link

lestoni commented Jun 14, 2016

If its only a component then you need to .empty() #reload element first before calling .load()

@Ammly
Copy link
Author

Ammly commented Jun 14, 2016

Just the component. <li class="disabled success" id="reload">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment