medarbejder list i php og ajax
Hej eksperter jeg er i gang med at lave en medarbejder list som ligger fast i min admin. Den bliver hentet og opdateret af en ajax code hvor jeg kalder et php script. Men kan ganske enkelt ikke få det til at blive vist. det er rigtig meget øv. for jeg har set den henter alle data og lægger i en array som bliver json_encode.men nu kommer lige mine koder til jer. håber i kan hjælpe.
employee_list.php
<?php
$con = mysqli_connect('localhost', 'jp_pro_dk', '****', 'jp_pro_dk');
if(mysqli_connect_errno()) {
die('kunne ikke forbinde til databasen: ' . mysqli_connect_error());
}
define('URL', 'http://jp-pro/');
$sql = "select * from employees";
$result = $con->query($sql);
$output = '';
$count = $result->num_rows;
if($count > 0) {
echo '
<li class="list-group-item list-group-item-secondary text-center" style="border-radius: 0">Medarbejder Liste</li>';
while ($dt = $result->fetch_array()) {
$status = $dt['status'];
$name = $dt['fname'].' '.$dt['sname']. ' '.$dt['lname'];
$role = $dt['role'];
$picture = $dt['picture'];
if($role === 'owner') {
$role = 'Direktør';
}
if($role === 'accountant') {
$role = 'Bogholder';
}
if($role === 'selling') {
$role = 'Sælger';
}
if($role === 'support') {
$role = 'Support';
}
if($role === 'technician') {
$role = 'Tekniker';
}
if($role === 'stock') {
$role = 'Lager';
}
if($role === 'programmer') {
$role = 'Programmør';
}
if(empty($picture)) {
$picture = 'nopic.jpg';
}
if($status === '1') {
$status = '<i class="fa fa-circle" style="color: green; font-style: normal;"></i> <i style="color: green; font-style: normal;">Online</i>';
$output .= '
<li class="list-group-item" style="border-radius: 0">
<img src="'.URL.'public/img/employee/'.$picture.'" width="30px" class="rounded rounded-circle" style="float: left;">
<span style="float: left; margin-left: 15px;">'.$name.'</span>
<span style="float: left; margin-left: 15px;">'.$status.' <i class="fa fa-flash" style="margin-left: 10px;"></i> '.$role.'</span>
</li>
';
} else {
$status = '<i class="fa fa-circle" style="color: red; font-style: normal;"></i> <i style="color: red; font-style: normal;">Offline</i>';
$output .= '
<li class="list-group-item" style="border-radius: 0">
<img src="'.URL.'public/img/employee/'.$picture.'" width="30px" class="rounded rounded-circle" style="float: left;">
<span style="float: left; margin-left: 15px;">'.$name.'</span>
<span style="float: left; margin-left: 15px;">'.$status.' <i class="fa fa-flash" style="margin-left: 10px;"></i> '.$role.'</span>
</li>
';
}
$data = array(
'emperlist' => $output
);
}
}
echo json_encode($data);
her kommer min js fil som hedder employee_list.js
$(document).ready(function () {
function load_employee_list(view) {
$.ajax({
url:'../views/admin/inc/data/employee_list.php',
type: 'post',
data:{view:view},
dataType:'json',
success:function (data) {
$('#employee_list').html(data.emperlist);
}
});
}
load_employee_list();
setInterval(function () {
load_employee_list()
}, 1000);
});
Det hele skal ligge i min employee_list som ligger i min header.php. den kommer her.
header.php
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<link rel="stylesheet" href="<?php echo URL; ?>public/css/styles.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<script src="<?php echo URL; ?>public/js/users.js"></script>
<script src="<?php echo URL; ?>public/js/employee_list.js"></script>
</head>
<body>
<div class="bg-dark" id="topbar">
<nav class="navbar navbar-expand-sm w-auto float-left">
<a href="<?php echo URL; ?>admin" class="navbar-brand" style="float: left;"><b class="text-primary">JP-PRO</b> <b class="text-light">SOFTWARE</b></a>
</nav>
<?php if(Session::get('adminLoggedIn') == true): ?>
<nav class="navbar navbar-expand-sm bg-dark navbar-dark justify-content-end">
<ul class="navbar-nav">
<li class="nav-item"><a href="#" class="nav-link fa fa-users" data-toggle="tooltip" data-placement="bottom" title="Vis/Skjul Messenger" onclick="myFunction()"></a></li>
<li class="nav-item"><a href="#" class="nav-link fa fa-globe"></a></li>
<li class="nav-item"><a href="#" class="nav-link fa fa-envelope"></a></li>
<li class="nav-item"><a href="<?php echo URL; ?>admin/logout" class="nav-link fa fa-sign-out"></a></li>
</ul>
</nav>
</div>
<aside class="bg-dark" id="sidebar">
<div class="list-group">
<?php if(Session::get('role') === 'owner'): ?>
<div class="dropdown list-group-item p-0 bg-dark">
<a href="#" class=" list-group-item list-group-item-action bg-dark text-light dropdown-toggle" style="border-radius: 0;" data-toggle="dropdown">Medarbejdere</a>
<div class="dropdown-menu">
<a href="<?php echo URL; ?>admin/all_employee" class="dropdown-item">Alle Medarbejdere</a>
<a href="<?php echo URL; ?>admin/new_employee" class="dropdown-item">Opret Medarbejder</a>
</div>
</div>
<?php endif; ?>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
<a href="#" class="list-group-item list-group-item-action bg-dark text-light" style="border-radius: 0;"">Menu Liste</a>
</div>
</aside>
<?php
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(mysqli_connect_errno()) {
die('Kunne ikke forbinde til ' . DB_NAME . ': ' . mysqli_connect_error());
}
?>
<aside id="messenger">
***************************************************************************************
<ul class="list-group" id="employee_list">
</ul>
***************************************************************************************
</aside>
<?php endif; ?>
Jeg håber i kan hjælpe med at få det løst. jeg kan simpelt hen ikke finde ud af hvad jeg har gjort forkert. På forhånd tak for hjælpen
Venlig hilsen
Delphiuser