

Tutaj link jak mniej więcej wygląda tabela

Kod
<?php
//include connection file
include_once("connection.php");
$sql = "SELECT * FROM pracownicy ORDER by wydzial_id ASC";
$queryRecords = mysqli_query($conn, $sql) or die("error to fetch employees data");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="sorttable.js"></script>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
<title>Lista</title>
<style type="text/css">
table {
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 14px;
background: #fff;
margin: 2px;
width: 780px;
border-collapse: collapse;
text-align: center;
}
tr:nth-child(2n) {
background-color: white;
}
tr:nth-child(2n+1) {
background-color: gray;
}
#hor-minimalist-a tbody tr:hover td
{
color: red;
}
</style>
</head>
<body>
<div class="container" style="padding:50px 250px;">
<h1>Lista pracowników</h1>
<div id="msg" class="alert"></div>
<table id="hor-minimalist-a" summary="Employee Pay Sheet" class="sortable">
<thead>
<tr align="left" valign="middle">
<th> <center> ID wydziału </th>
<th> <center> Imię </th>
<th> <center>Nazwisko </th>
<th> <center> Numer wewnetrzny </th>
<th> <center> Stanowisko </th>
<th> <center> Numer pokoju </th>
</tr></center>
</thead>
<center>
<tbody>
<tr> <th colspan ="8"><center>Wydział Główny</th> </tr>
<?php foreach($queryRecords as $res) :?>
<tr data-row-id="<?php echo $res['pracownicy_id'];?>" align="center">
<td class="editable-col" contenteditable="true" col-index='2' oldVal ="<?php echo $res['wydzial_id'];?>"><?php echo $res['wydzial_id'];?></td>
<td class="editable-col" contenteditable="true" col-index='0' oldVal ="<?php echo $res['imie'];?>"><?php echo $res['imie'];?></td>
<td class="editable-col" contenteditable="true" col-index='1' oldVal ="<?php echo $res['nazwisko'];?>"><?php echo $res['nazwisko'];?></td>
<td class="editable-col" contenteditable="true" col-index='3' oldVal ="<?php echo $res['numer_wewnetrzny'];?>"><?php echo $res['numer_wewnetrzny'];?></td>
<td class="editable-col" contenteditable="true" col-index='4' oldVal ="<?php echo $res['stanowisko'];?>"><?php echo $res['stanowisko'];?></td>
<td class="editable-col" contenteditable="true" col-index='5' oldVal ="<?php echo $res['numer_pokoju'];?>"><?php echo $res['numer_pokoju'];?></td>
<?php endforeach;?>
//no i tutaj jest problem bo mam foreach i nawet jak w srodku dam tr hr cokolwiek klonuje mi to i dupa :(
</tbody> </center></tr>
</table>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$('td.editable-col').on('focusout', function() {
data = {};
data['val'] = $(this).text();
data['id'] = $(this).parent('tr').attr('data-row-id');
data['index'] = $(this).attr('col-index');
if($(this).attr('oldVal') === data['val'])
return false;
$.ajax({
type: "POST",
url: "server.php",
cache:false,
data: data,
dataType: "json",
success: function(response)
{
//$("#loading").hide();
if(!response.error) {
$("#msg").removeClass('alert-danger');
$("#msg").addClass('alert-success').html(response.msg);
} else {
$("#msg").removeClass('alert-success');
$("#msg").addClass('alert-danger').html(response.msg);
}
}
});
});
});
</script>
//include connection file
include_once("connection.php");
$sql = "SELECT * FROM pracownicy ORDER by wydzial_id ASC";
$queryRecords = mysqli_query($conn, $sql) or die("error to fetch employees data");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="sorttable.js"></script>
<script type="text/javascript" src="jquery-1.11.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css"/>
<title>Lista</title>
<style type="text/css">
table {
font-family: "Lucida Sans Unicode", "Lucida Grande", Sans-Serif;
font-size: 14px;
background: #fff;
margin: 2px;
width: 780px;
border-collapse: collapse;
text-align: center;
}
tr:nth-child(2n) {
background-color: white;
}
tr:nth-child(2n+1) {
background-color: gray;
}
#hor-minimalist-a tbody tr:hover td
{
color: red;
}
</style>
</head>
<body>
<div class="container" style="padding:50px 250px;">
<h1>Lista pracowników</h1>
<div id="msg" class="alert"></div>
<table id="hor-minimalist-a" summary="Employee Pay Sheet" class="sortable">
<thead>
<tr align="left" valign="middle">
<th> <center> ID wydziału </th>
<th> <center> Imię </th>
<th> <center>Nazwisko </th>
<th> <center> Numer wewnetrzny </th>
<th> <center> Stanowisko </th>
<th> <center> Numer pokoju </th>
</tr></center>
</thead>
<center>
<tbody>
<tr> <th colspan ="8"><center>Wydział Główny</th> </tr>
<?php foreach($queryRecords as $res) :?>
<tr data-row-id="<?php echo $res['pracownicy_id'];?>" align="center">
<td class="editable-col" contenteditable="true" col-index='2' oldVal ="<?php echo $res['wydzial_id'];?>"><?php echo $res['wydzial_id'];?></td>
<td class="editable-col" contenteditable="true" col-index='0' oldVal ="<?php echo $res['imie'];?>"><?php echo $res['imie'];?></td>
<td class="editable-col" contenteditable="true" col-index='1' oldVal ="<?php echo $res['nazwisko'];?>"><?php echo $res['nazwisko'];?></td>
<td class="editable-col" contenteditable="true" col-index='3' oldVal ="<?php echo $res['numer_wewnetrzny'];?>"><?php echo $res['numer_wewnetrzny'];?></td>
<td class="editable-col" contenteditable="true" col-index='4' oldVal ="<?php echo $res['stanowisko'];?>"><?php echo $res['stanowisko'];?></td>
<td class="editable-col" contenteditable="true" col-index='5' oldVal ="<?php echo $res['numer_pokoju'];?>"><?php echo $res['numer_pokoju'];?></td>
<?php endforeach;?>
//no i tutaj jest problem bo mam foreach i nawet jak w srodku dam tr hr cokolwiek klonuje mi to i dupa :(
</tbody> </center></tr>
</table>
</div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function(){
$('td.editable-col').on('focusout', function() {
data = {};
data['val'] = $(this).text();
data['id'] = $(this).parent('tr').attr('data-row-id');
data['index'] = $(this).attr('col-index');
if($(this).attr('oldVal') === data['val'])
return false;
$.ajax({
type: "POST",
url: "server.php",
cache:false,
data: data,
dataType: "json",
success: function(response)
{
//$("#loading").hide();
if(!response.error) {
$("#msg").removeClass('alert-danger');
$("#msg").addClass('alert-success').html(response.msg);
} else {
$("#msg").removeClass('alert-success');
$("#msg").addClass('alert-danger').html(response.msg);
}
}
});
});
});
</script>
a tutaj 2 plik odpowiadający za indexowanie kolumn w moim przypadku , uzywam do tego jquery+ajax (interaktywna edytująca sie tabela).
Kod
<?php
//include connection file
include_once("connection.php");
//define index of column
$columns = array(
0 =>'imie',
1 => 'nazwisko',
2 => 'wydzial_id',
3 => 'numer_wewnetrzny',
4 => 'stanowisko',
5 => 'numer_pokoju'
);
$error = false;
$colVal = '';
$colIndex = $rowId = 0;
$msg = array('status' => !$error, 'msg' => 'Blad! update nie powiodl sie');
if(isset($_POST)){
if(isset($_POST['val']) && !empty($_POST['val']) && !$error) {
$colVal = $_POST['val'];
$error = false;
} else {
$error = true;
}
if(isset($_POST['index']) && $_POST['index'] >= 0 && !$error) {
$colIndex = $_POST['index'];
$error = false;
} else {
$error = true;
}
if(isset($_POST['id']) && $_POST['id'] > 0 && !$error) {
$rowId = $_POST['id'];
$error = false;
} else {
$error = true;
}
if(!$error) {
$sql = "UPDATE pracownicy SET ".$columns[$colIndex]." = '".$colVal."' WHERE pracownicy_id='".$rowId."'";
$status = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
$msg = array('error' => $error, 'msg' => 'Sukces! Zakonczono powodzeniem');
} else {
$msg = array('error' => $error, 'msg' => 'Blad! update nie powiodl sie');
}
}
// send data as json format
echo json_encode($msg);
?>
//include connection file
include_once("connection.php");
//define index of column
$columns = array(
0 =>'imie',
1 => 'nazwisko',
2 => 'wydzial_id',
3 => 'numer_wewnetrzny',
4 => 'stanowisko',
5 => 'numer_pokoju'
);
$error = false;
$colVal = '';
$colIndex = $rowId = 0;
$msg = array('status' => !$error, 'msg' => 'Blad! update nie powiodl sie');
if(isset($_POST)){
if(isset($_POST['val']) && !empty($_POST['val']) && !$error) {
$colVal = $_POST['val'];
$error = false;
} else {
$error = true;
}
if(isset($_POST['index']) && $_POST['index'] >= 0 && !$error) {
$colIndex = $_POST['index'];
$error = false;
} else {
$error = true;
}
if(isset($_POST['id']) && $_POST['id'] > 0 && !$error) {
$rowId = $_POST['id'];
$error = false;
} else {
$error = true;
}
if(!$error) {
$sql = "UPDATE pracownicy SET ".$columns[$colIndex]." = '".$colVal."' WHERE pracownicy_id='".$rowId."'";
$status = mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));
$msg = array('error' => $error, 'msg' => 'Sukces! Zakonczono powodzeniem');
} else {
$msg = array('error' => $error, 'msg' => 'Blad! update nie powiodl sie');
}
}
// send data as json format
echo json_encode($msg);
?>
EDIT: Czy jest jakiś sposób na posegregować stanowiskami danych userów? Chodzi mi o to by dyrektor zawsze był na 1 miejscu a kierownik ew. na 3 , stworzyć taka hierarchie tak jak w wojsku od szeregowego aż po generała ?
