How to create an members list from the mysql table. I used this code an it gives me an white page.
<?php
$sql = new mysqli('localhost','DB-USER','PASS','DB'); /
$sql -> set_charset ( 'utf8' );
if ($sql->connect_errno) {
printf("Connect failed: %s\n", $sql->connect_error);
exit();
}
while ($fetch = $profile_query_check->fetch (PDO::FETCH_ASSOC)) {
if ($fetch == NULL OR $fetch["id"]) {
break;
}
$username = $fetch['username'];
$avatar = $fetch['avatar'];
$id = $fetch['id'];
//echo the profile info
}
?>
And this the user table
CREATE TABLE IF NOT EXISTS `users` (
`id` int(50) NOT NULL,
`level` int(11) NOT NULL,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
`usertype` int(11) NOT NULL,
`rpname` varchar(50) NOT NULL,
`fbname` varchar(50) NOT NULL,
`avatar` varchar(100) NOT NULL,
`avatarchangedate` int(11) NOT NULL,
`new_activity_count` int(11) NOT NULL,
`online` tinyint(4) NOT NULL,
) ENGINE=MyISAM AUTO_INCREMENT=13397 DEFAULT CHARSET=utf8;
Please help me how to create the code? I'm noob
Update: But this whoisisonline code is working
<?php
if(!defined('A')){
include "error.php";die(header('HTTP/1.0 403 Forbidden'));
}
global $sql;
//http://ift.tt/1GXGfOs
//Checks the sesson file to see how many files there are
function usersonline() {
$sessionfiles = session_save_path() . "/sess*";
$usersonline = count(glob($sessionfiles));
return $usersonline;
}
if(isset(user::$current->id)){
$current_ID = user::$current->id;
}else{
$current_ID = "";
}
$sql->run("select_who_is_online", array(
"userID" => $current_ID,
"time" => (time() - 180)
));
// $sql->last_query_info();
$users = $sql->fetch_array();
$count = count($users);
$members_online = $count;
if (user::$loggedIn) {
$members_online++;
}
$vistors_online = (usersonline() - $members_online);
//plural check
if ($members_online == 0)
$members_online_message = "There are currently no NEETs online";
else if ($members_online == 1)
$members_online_message = "There is currently only one NEET online";
else
$members_online_message = "There are currently ".$members_online." NEETs online";
if($vistors_online == 1)
$vistors_online_message = "and ".$vistors_online." Person passing by";
else
$vistors_online_message = "and ".$vistors_online." People passing by";
echo "<div class='content_header blue small align_left' style='margin-top: 20px;'>Who is Online";
echo "<x style='float:right;margin-right:8px'>".$members_online_message.", ". $vistors_online_message ."<x>";
echo "</div>";
// echo "<h1 class='content_centered'>Who is Online</h1><br/>";
echo "<div class='content_padded content_centered content_feed light'>";
if($count){
foreach($users as $user){
// print_r($user);
$user_obj = new user($user["id"]);
$gUser = new gUser($user_obj);
$tmp = '';
$tmp .= "<div style='text-align: center; display: inline-block; width: 110px; margin-bottom: 10px;'>";
// if ($friend->online)
$tmp .= "<div class='basicSuccess' style='display: block; margin-bottom: 3px; width: 73px;'><i class='fa fa-wifi'></i> Online</div>";
$tmp .= $gUser->htmlAvatar(70, "middle");
$tmp .= "<div style='margin-top: 5px;'>" . $gUser->htmlSmall() . "</div>";
$tmp .= "</div>";
echo $tmp;
}
}else if(user::$loggedIn){
echo "<h5>No one else is online T^T</h5>";
}else {
echo "<h5>No one is online T~T</h5>";
}
echo "</div>";
?>
Aucun commentaire:
Enregistrer un commentaire