Load data on bootstrap-table - php

I have made a website with bootstrap framework. In this website I load a table with records of the database, I using php for this.
My question is: php is the best way to load a data on the table or there are a better option?
Also when it's load the data in the website, first it show the text without format and after 1 second show with the css styles :(
This is the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AddCloud - Edicions</title>
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/bootstrap-table/dist/bootstrap-table.css">
</head>
<body>
<?php
session_start();
if(isset($_SESSION['username']) and $_SESSION['username'] <> ''){
?>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#defaultNavbar1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
<a class="navbar-brand" href="http://www.addvantage.es"><font color=#8abe44>AddCloud</font></a></div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="defaultNavbar1">
<ul class="nav navbar-nav">
<li class="active">Edicions<span class="sr-only">(current)</span></li>
<li>Productes</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"><span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION['username'] ?>
<ul class="dropdown-menu" role="menu">
<li><span class="glyphicon glyphicon-wrench"></span> preferències</li>
<li><span class="glyphicon glyphicon-lock"></span> canviar password</li>
<li class="divider"></li>
<li><span class="glyphicon glyphicon-log-out"></span> log out</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1 class="text-center">Miquel Alimentació</h1>
</div>
</div>
<hr>
</div>
<div class="container">
<div class="row text-center">
<div class="col-md-6 col-md-offset-3"><h3>Edició 12</h3></div>
</div>
<hr>
<div class="row">
<?php
// Conexió a la base de dades
include("connect.php");
$conn = Conectarse("localhost", "5432", "dbname", "dbuser", "dbpass");
//query
$query = "SELECT * FROM produccion.ma_origen ORDER BY id_articulo ASC";
$result = pg_query($conn, $query);
//se despliega el resultado
echo "<table id='table'
data-toggle='table'
data-toolbar='#toolbar'
data-show-refresh='true'
data-show-toggle='true'
data-sort-name='name'
data-sort-order='desc'
data-show-columns='true'
data-pagination='true'
data-search='true'
data-click-to-select='true'>";
echo "<thead class='thead-inverse'>";
echo "<tr>";
echo "<th data id='seleccion' data-switchable='false' data-checkbox='true'></th>";
echo "<th data id='pagina' data-sortable='true'>pagina</th>";
echo "<th data id='codigo' data-sortable='true' data-switchable='false'>codigo</th>";
echo "<th data id='descripcion' data-sortable='true' data-switchable='false'>descripcion</th>";
echo "<th data id='pvp-cat' data-sortable='true'>pvp-cat</th>";
echo "<th data id='pvp-lev' data-sortable='true'>pvp-lev</th>";
echo "<th data id='pvp-and' data-sortable='true'>pvp-and</th>";
echo "<th data id='pvp-cen' data-sortable='true'>pvp-cen</th>";
echo "<th data id='pvp-nor' data-sortable='true'>pvp-nor</th>";
echo "<th data id='pvp-vas' data-sortable='true'>pvp-vas</th>";
echo "<th data id='fecha-mod' data-sortable='true'>fecha-mod</th>";
echo "<th data id='user' data-sortable='true' data-visible='false'>user</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = pg_fetch_row($result)){
echo "<tr>";
echo "<td></td>";
echo "<td>$row[2]></td>";
echo "<td>$row[3]</td>";
echo "<td>$row[4]</td>";
echo "<td>$row[5]</td>";
echo "<td>$row[6]</td>";
echo "<td>$row[7]></td>";
echo "<td>$row[8]</td>";
echo "<td>$row[9]</td>";
echo "<td>$row[10]</td>";
echo "<td>$row[11]</td>";
echo "<td>$row[12]</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>
<hr>
<div class="row">
<div class="text-center col-md-6 col-md-offset-3">
<p>Copyright © 2016 · All Rights Reserved · <a href="http://www.addvantage.es/" >http://www.addvantage.es</a></p>
</div>
</div>
<hr>
</div>
<script>
$("td").dblclick(function(){
alert("The paragraph was double-clicked");
});
</script>
<script src="assets/jquery/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/bootstrap-table/dist/bootstrap-table.js"></script>
<?php
} else{
?><p>La sesión no está activa, por favor ingrese aquí</p>
<?php
}?>
</body>
</html>
Please Could you help me with this issues?
Thanks!

As for your question:
"My question is: php is the best way to load a data on the table or there are a better option?"
A: If you are loading dynamic data that is retrieved from a source (eg: database or a file), then the best way (or the only way) to do this is through a scripting language like PHP as you have mentioned.

Get your data with Ajax, and using .append()* function (jQuery), fill the table on $(document).ready() or any other triggered event.
*
jQuery.each(data, function(index, value) {
$("#table_div").append("<tr><td>" + value + "</td></tr>");
});
You can check the example below.
var mydata = [{"Nome":"",
"Cognome":"",
"DataN":"0000-00-00",
"Provincia":"",
"Comune":"",
"CAP":"",
"Indirizzo":"",
"Fisso":"",
"Mobile":"",
"Note":""},
{"Nome":"Federico",
"Cognome":"Lupieri",
"DataN":"2015-09-16",
"Provincia":"",
"Comune":"",
"CAP":"34170",
"Indirizzo":"Via Ascoli 1",
"Fisso":"00112233445566",
"Mobile":"00112233445566",
"Note":"Vediamo se funziona questo"}];
$(document).ready(function(){
$.ajax({
url: '/echo/json/',
dataType: 'json',
success: function(data) {
//alert('done');
$('#clienti').bootstrapTable({
data: mydata
});
},
error: function(e) {
console.log(e.responseText);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="display table table-bordered" id="clienti">
<thead>
<tr>
<th data-field="Nome">Nome</th>
<th data-field="Cognome">Cognome</th>
<th data-field="DataN">Data Nascita</th>
<th data-field="Provincia">Provincia</th>
<th data-field="Comune">Comune</th>
<th data-field="CAP">CAP</th>
<th data-field="Indirizzo">Indirizzo</th>
<th data-field="Fisso">Fisso</th>
<th data-field="Mobile">Cellulare</th>
<th data-field="Note">Note</th>
</tr>
</thead>
</table>
Get your data with Ajax and then fill your table directly, so any data that will be seen on website will be sorted in the table.

Related

problem with Warning: session_start(): Cannot send session cache limiter - headers already sent [duplicate]

This question already has answers here:
PHP headers already sent [duplicate]
(4 answers)
Closed 2 years ago.
when i running my project i got errorr like this
warning: session_start(): Cannot send session cache limiter - headers
already sent (output started at
C:\xampp\htdocs\skripsieka\file1.php:125) in
C:\xampp\htdocs\skripsieka\file2.php on line 2
what reason for this? and how to fix it
this the code
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>SPK topsis</title>
<!-- plugins:css -->
<link rel="stylesheet" href="assets/vendors/mdi/css/materialdesignicons.min.css">
<link rel="stylesheet" href="assets/vendors/css/vendor.bundle.base.css">
<!-- endinject -->
<!-- Plugin css for this page -->
<!-- End plugin css for this page -->
<!-- inject:css -->
<!-- endinject -->
<!-- Layout styles -->
<link rel="stylesheet" href="assets/css/style.css">
<!-- End layout styles -->
<link rel="shortcut icon" href="assets/images/favicon.png" />
</head>
<?php
if(#$_GET['a']=='kriteria'){
$active1='class="active"';
$active2='';
$active3='';
$active4='';
}else if(#$_GET['a']=='alternatif'){
$active1='';
$active2='class="active"';
$active3='';
$active4='';
}else if(#$_GET['a']=='nilaimatrik'){
$active1='';
$active2='';
$active3='class="active"';
$active4='';
}else if(#$_GET['a']=='hasiltopsis'){
$active1='';
$active2='';
$active3='';
$active4='class="active"';
}else{
$active1='';
$active2='';
$active3='';
$active4='';
}
?>
<div class="container-scroller">
<!-- partial:partials/_navbar.html -->
<nav class="navbar default-layout-navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
<div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
<a class="navbar-brand brand-logo" href="index.html"><img src="assets/images/logo.svg" alt="logo" /></a>
<a class="navbar-brand brand-logo-mini" href="index.html"><img src="assets/images/logo-mini.svg" alt="logo" /></a>
</div>
<div class="navbar-menu-wrapper d-flex align-items-stretch">
<button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
<span class="mdi mdi-menu"></span>
</button>
<div class="search-field d-none d-md-block">
<form class="d-flex align-items-center h-100" action="#">
<div class="input-group">
<div class="input-group-prepend bg-transparent">
<i class="input-group-text border-0 mdi mdi-magnify"></i>
</div>
<input type="text" class="form-control bg-transparent border-0" placeholder="Search projects">
</div>
</form>
</div>
<ul class="navbar-nav navbar-nav-right">
<li class="nav-item nav-logout d-none d-lg-block">
<a class="nav-link" href="logout.php">
<i class="mdi mdi-power"></i>
</a>
</li>
</ul>
</div>
</nav>
<!-- partial -->
<div class="container-fluid page-body-wrapper">
<!-- partial:partials/_sidebar.html -->
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<ul class="nav">
<li class="nav-item nav-profile">
<a href="#" class="nav-link">
<div class="nav-profile-image">
<img src="assets/images/faces/face1.jpg" alt="profile">
<span class="login-status online"></span>
<!--change to offline or busy as needed-->
</div>
<div class="nav-profile-text d-flex flex-column">
<span class="font-weight-bold mb-2">Admin</span>
<span class="text-secondary text-small">eka amaliyah</span>
</div>
<i class="mdi mdi-bookmark-check text-success nav-profile-badge"></i>
</a>
</li>
<li <?php echo $active1 ?> class="nav-item">
<a class="nav-link" href="?a=kriteria&k=kriteria" >
<span class="menu-title">Kriteria</span>
<i class="mdi mdi-home menu-icon"></i>
</a>
</li>
<li <?php echo $active2 ?> class="nav-item">
<a class="nav-link" data-toggle="collapse" href="?a=alternatif&k=alternatif" aria-expanded="false" aria-controls="ui-basic">
<span class="menu-title">Data Kepala Keluarga</span>
<i class="menu-arrow"></i>
<i class="mdi mdi-crosshairs-gps menu-icon"></i>
</a>
</li>
<li <?php echo $active3 ?> class="nav-item">
<a class="nav-link" href="?a=nilaimatrik">
<span class="menu-title">Nilai matriks</span>
<i class="mdi mdi-contacts menu-icon"></i>
</a>
</li>
<li <?php echo $active4 ?> class="nav-item">
<a class="nav-link" href="?a=hasiltopsis&k=nilai_matriks">
<span class="menu-title">Hasil Topsis</span>
<i class="mdi mdi-format-list-bulleted menu-icon"></i>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="pages/charts/chartjs.html">
<span class="menu-title">Charts</span>
<i class="mdi mdi-chart-bar menu-icon"></i>
</a>
</li>
</ul>
</nav>
<!-- partial -->
<div class="main-panel">
<div class="content-wrapper">
<div class="col-12 grid-margin">
<div class="card">
<div class="card-body">
<?php
if(#$_GET['a']=='kriteria'){
include ("kriteria.php");
}else if(#$_GET['a']=='alternatif'){
include ("alternatif.php");
}else if(#$_GET['a']=='nilaimatrik'){
include ("nilaimatrik.php");
}else if(#$_GET['a']=='hasiltopsis'){
include ("hasiltopsis.php");
}
?>
</div>
</div>
</div>
<!-- content-wrapper ends -->
<!-- partial:partials/_footer.html -->
<footer class="footer">
<div class="d-sm-flex justify-content-center justify-content-sm-between">
<span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © 2020 Eka amaliyah. All rights reserved.</span>
<span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">I made it with <i class="mdi mdi-heart text-danger"></i></span>
</div>
</footer>
<!-- partial -->
</div>
<!-- main-panel ends -->
</div>
<!-- page-body-wrapper ends -->
</div>
<!-- TAB KIRI -->
<!-- /TAB KIRI -->
<
</div>
<!-- container-scroller -->
<!-- plugins:js -->
<script src="../../assets/vendors/js/vendor.bundle.base.js"></script>
<!-- endinject -->
<!-- Plugin js for this page -->
<!-- End plugin js for this page -->
<!-- inject:js -->
<script src="../../assets/js/off-canvas.js"></script>
<script src="../../assets/js/hoverable-collapse.js"></script>
<script src="../../assets/js/misc.js"></script>
<!-- endinject -->
<!-- Custom js for this page -->
<!-- End custom js for this page -->
</body>
</html>
and this the page when error came
<?php
session_start();
include ("konfig/koneksi.php");
$s=mysqli_query($conn,"select * from kriteria");
$h=mysqli_num_rows($s);
?>
<div class="box-header">
<h3 class="box-title " >Jarak Solusi Ideal Positif (D<sup>+</sup>)</h3>
</div>
<table class="table table-bordered table-responsive">
<thead>
<tr>
<th >Nomor</th>
<th >Nama</th>
<th >D<sup>+</sup></th>
</tr>
</thead>
<tbody>
<?php
//buat array kolom
$i2=1;
$i3=0;
$maxarray=array();
$a2=mysqli_query($conn,"select * from kriteria");
echo "<tr>";
while($da2=mysqli_fetch_assoc($a2)){
$idalt2=$da2['id_kriteria'];
//ambil nilai
$n2=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idalt2'");
$jarakp2=0;
$c2=0;
$ymax2=array();
while($dn2=mysqli_fetch_assoc($n2)){
$idk2=$dn2['id_kriteria'];
//nilai kuadrat
$nilai_kuadrat2=0;
$k2=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk2' ");
while($dkuadrat2=mysqli_fetch_assoc($k2)){
$nilai_kuadrat2=$nilai_kuadrat2+($dkuadrat2['nilai']*$dkuadrat2['nilai']);
}
//hitung jml alternatif
$jml_alternatif2=mysqli_query($conn,"select * from alternatif");
$jml_a2=mysqli_num_rows($jml_alternatif2);
//nilai bobot kriteria (rata")
$bobot2=0;
$tnilai2=0;
$k22=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk2' ");
while($dbobot2=mysqli_fetch_assoc($k22)){
$tnilai2=$tnilai2+$dbobot2['nilai'];
}
$bobot2=$tnilai2/$jml_a2;
//nilai bobot input
$b2=mysqli_query($conn,"select * from kriteria where id_kriteria='$idk2'");
$nbot2=mysqli_fetch_assoc($b2);
$bot2=$nbot2['bobot'];
$v2=round(($dn2['nilai']/sqrt($nilai_kuadrat2))*$bot2,3);
$ymax2[$c2]=$v2;
$c2++;
#cek benefit atau cost
// echo $nbot2['sifat']." - ".$nbot2['nama_kriteria']."<br>";
if($nbot2['sifat']=='benefit'){
$mak2=max($ymax2);
}else{
$mak2=min($ymax2);
}#cek benefit atau cost
}
//hitung D+
foreach($ymax2 as $nymax2){
$jarakp2=$jarakp2+pow($nymax2-$mak2,2);
}
//array max
$maxarray[$i3]=max($ymax2);
//print_r($maxarray);
//print_r(max($ymax2));
$i2++;
$i3++;
}
//session array ymax
$_SESSION['ymax']=$maxarray;
//array baris//////////////////////////////////////////////////
$i=1;
$ii=0;
$dpreferensi=array();
$a=mysqli_query($conn,"select * from alternatif");
echo "<tr>";
while($da=mysqli_fetch_assoc($a)){
$idalt=$da['id_alternatif'];
//ambil nilai
$n=mysqli_query($conn,"select * from nilai_matrik where id_alternatif='$idalt'");
$jarakp=0;
$c=0;
$ymax=array();
$arraymaks=array();
while($dn=mysqli_fetch_assoc($n)){
$idk=$dn['id_kriteria'];
//nilai kuadrat
$nilai_kuadrat=0;
$k=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk' ");
while($dkuadrat=mysqli_fetch_assoc($k)){
$nilai_kuadrat=$nilai_kuadrat+($dkuadrat['nilai']*$dkuadrat['nilai']);
}
//hitung jml alternatif
$jml_alternatif=mysqli_query($conn,"select * from alternatif");
$jml_a=mysqli_num_rows($jml_alternatif);
//nilai bobot kriteria (rata")
$bobot=0;
$tnilai=0;
$k2=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk' ");
while($dbobot=mysqli_fetch_assoc($k2)){
$tnilai=$tnilai+$dbobot['nilai'];
}
$bobot=$tnilai/$jml_a;
//nilai bobot input
$b2=mysqli_query($conn,"select * from kriteria where id_kriteria='$idk'");
$nbot=mysqli_fetch_assoc($b2);
$bot=$nbot['bobot'];
$v=round(($dn['nilai']/sqrt($nilai_kuadrat))*$bot,3);
$ymax[$c]=$v;
$c++;
$mak=max($ymax);
}
//hitung D+
foreach($ymax as $nymax=>$value){
$maks=$_SESSION['ymax'][$nymax];
//echo $maks." - ";
$final=sqrt($jarakp=$jarakp+pow($value-$maks,2));
//echo $jarakp." || ";
}
echo "<tr>
<td>$i</td>
<td>$da[nm_alternatif]</td>
<td>".round($final,3)."</td>
</tr>";
$dpreferensi[$ii]=round($final,3);
$_SESSION['dplus']=$dpreferensi;
//print_r($ymax);
$i++;
$ii++;
}
echo "</tr>";
?>
</tbody>
</table>
<!-- tabel min ------------------------------------------------->
<div class="box-header">
<h3 class="box-title " >Jarak Solusi Ideal Negatif (D<sup>-</sup>)</h3>
</div>
<table class="table table-bordered table-responsive">
<thead>
<tr>
<th >Nomor</th>
<th >Nama</th>
<th >D<sup>-</sup></th>
</tr>
</thead>
<tbody>
<?php
//buat array kolom
$i2=1;
$i3=0;
$minarray=array();
$a2=mysqli_query($conn,"select * from kriteria");
echo "<tr>";
while($da2=mysqli_fetch_assoc($a2)){
$idalt2=$da2['id_kriteria'];
//ambil nilai
$n2=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idalt2'");
$jarakp2=0;
$c2=0;
$ymin2=array();
while($dn2=mysqli_fetch_assoc($n2)){
$idk2=$dn2['id_kriteria'];
//nilai kuadrat
$nilai_kuadrat2=0;
$k2=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk2' ");
while($dkuadrat2=mysqli_fetch_assoc($k2)){
$nilai_kuadrat2=$nilai_kuadrat2+($dkuadrat2['nilai']*$dkuadrat2['nilai']);
}
//hitung jml alternatif
$jml_alternatif2=mysqli_query($conn,"select * from alternatif");
$jml_a2=mysqli_num_rows($jml_alternatif2);
//nilai bobot kriteria (rata")
$bobot2=0;
$tnilai2=0;
$k22=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk2' ");
while($dbobot2=mysqli_fetch_assoc($k22)){
$tnilai2=$tnilai2+$dbobot2['nilai'];
}
$bobot2=$tnilai2/$jml_a2;
//nilai bobot input
$b2=mysqli_query($conn,"select * from kriteria where id_kriteria='$idk2'");
$nbot2=mysqli_fetch_assoc($b2);
$bot2=$nbot2['bobot'];
$v2=round(($dn2['nilai']/sqrt($nilai_kuadrat2))*$bot2,3);
$ymin2[$c2]=$v2;
$c2++;
$min2=min($ymin2);
}
//hitung D+
foreach($ymin2 as $nymin2){
$jarakp2=$jarakp2+pow($nymin2-$min2,2);
//echo "--".$mak."---";
}
//array max
$minarray[$i3]=min($ymin2);
//print_r($maxarray);
//print_r(max($ymax2));
$i2++;
$i3++;
}
//session array ymax
$_SESSION['ymin']=$minarray;
//array baris//////////////////////////////////////////////////
$i=1;
$ii=0;
$id_alt=array();
$a=mysqli_query($conn,"select * from alternatif");
echo "<tr>";
while($da=mysqli_fetch_assoc($a)){
$idalt=$da['id_alternatif'];
//ambil nilai
$n=mysqli_query($conn,"select * from nilai_matrik where id_alternatif='$idalt'");
$jarakp=0;
$c=0;
$ymax=array();
$arraymin=array();
while($dn=mysqli_fetch_assoc($n)){
$idk=$dn['id_kriteria'];
//nilai kuadrat
$nilai_kuadrat=0;
$k=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk' ");
while($dkuadrat=mysqli_fetch_assoc($k)){
$nilai_kuadrat=$nilai_kuadrat+($dkuadrat['nilai']*$dkuadrat['nilai']);
}
//hitung jml alternatif
$jml_alternatif=mysqli_query($conn,"select * from alternatif");
$jml_a=mysqli_num_rows($jml_alternatif);
//nilai bobot kriteria (rata")
$bobot=0;
$tnilai=0;
$k2=mysqli_query($conn,"select * from nilai_matrik where id_kriteria='$idk' ");
while($dbobot=mysqli_fetch_assoc($k2)){
$tnilai=$tnilai+$dbobot['nilai'];
}
$bobot=$tnilai/$jml_a;
//nilai bobot input
$b2=mysqli_query($conn,"select * from kriteria where id_kriteria='$idk'");
$nbot=mysqli_fetch_assoc($b2);
$bot=$nbot['bobot'];
$v=round(($dn['nilai']/sqrt($nilai_kuadrat))*$bot,3);
$ymin[$c]=$v;
$c++;
$min=max($ymin);
}
//hitung D+
foreach($ymin as $nymin=>$value){
$mins=$_SESSION['ymin'][$nymin];
// echo $mins." - ";
$final=sqrt($jarakp=$jarakp+pow($value-$mins,2));
// echo $jarakp." || ";
}
echo "<tr>
<td>$i</td>
<td>$da[nm_alternatif]</td>
<td>".round($final,3)."</td>
</tr>";
//session min
$dpreferensi[$ii]=round($final,3);
$_SESSION['dmin']=$dpreferensi;
//print_r($ymin);
//ambil id alternatif
$id_alt[$ii]=$da['id_alternatif'];
$_SESSION['id_alt']=$id_alt;
$i++;
$ii++;
}
echo "</tr>";
?>
</tbody>
</table>
This error usually comes when the session_start() is not declared at the very beginning of the page and the php script is already sent to HTTP headers. You must start the session at the very beginning of the page.
You should use
if(!isset($_SESSION))
{
session_start();
}
may be it works
Check that session_start() is written at the top of the file and nothing else is printed before that.
Looking at your code, session_start() is written at the top but may be an error is occurring which is printing that error before session. Please enable display of error and error reporting to check using below code.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(-1);

HTML table not populating from mysql db

I am trying to get a simple HTML table of the data in a table of my mysql database, but it is just showing up as a jumbled mess of the text and code in a paragraph on the page. Any ideas what may be causing this? Below is the code I am running:
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Title
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="./swipe_da_code_files/bootstrap.min.css" rel="stylesheet">
<link rel="icon" type="image/ico" href="http://lndapp.wpi.edu/img/favicon.ico">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://url:Port">AdminPortal</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Create User</li>
<li>Database</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<h1>Database Landing Page</h1>
</div>
<?php
$server = mysql_connect("server", "user", "password");
$db = mysql_select_db("database", $server);
$query = mysql_query("SELECT * FROM Table");
?>
<table>
<tr>
<td>username</td>
<td>password</td>
<td>physicianID</td>
</tr>
<?php
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>".$row[username]."</td>";
echo "<td>".$row[password]."</td>";
echo "<td>".$row[physicianID]."</td>";
echo "</tr>";
}
?>
</table>
</body></html>
I have tried a variety of different ways to display the data, this was the most simple form I could think of to just display a few rows in table form, however it is not running. I have double checked my connection details I entered, as well as the query for the database, and am certain that is not what's causing it.
Replace
echo "<td>".$row[username]."</td>";
echo "<td>".$row[password]."</td>";
echo "<td>".$row[physicianID]."</td>";
By
echo "<td>".$row['username']."</td>";
echo "<td>".$row['password']."</td>";
echo "<td>".$row['physicianID']."</td>";
You are missing quotes!
Please use mysqli or PDO since mysl method is now deprecated.
<?php
$server=mysqli_connect("server", "user", "password" , "my_db");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($server, "SELECT * FROM Table")
?>
then
<?php
while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row['username']."</td>";
echo "<td>".$row['password']."</td>";
echo "<td>".$row['physicianID']."</td>";
echo "</tr>";
}
?>
Akintunde007 is correct in his/her answer that you are parsing a constant.

Bootstrap-table - Modify fields with bootstrap modal

I continue with my new website and I'm trying the bootstrap framework and I would like modify a row, its fields, from a bootstrap modal window. At moment I show a modal windows with fields but I don't know to include the data from the row of the table :(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AddCloud - Producció</title>
<!-- INCLUDES -->
<link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/bootstrap-table/dist/bootstrap-table.css">
<link rel="stylesheet" href="assets/bootstrap-editable/css/bootstrap-editable.css">
<script src="assets/jquery/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/bootstrap-table/dist/bootstrap-table.js"></script>
<script src="assets/bootstrap-editable/js/bootstrap-editable.js"></script>
</head>
<body>
<!-- SESSION PHP OK -->
<?php
session_start();
if(isset($_SESSION['username']) and $_SESSION['username'] <> ''){
?>
<!-- NAVIGATION -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#defaultNavbar1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
<a class="navbar-brand" href="http://www.addvantage.es"><font color=#8abe44>AddCloud</font></a></div>
<div class="collapse navbar-collapse" id="defaultNavbar1">
<ul class="nav navbar-nav">
<li class="active">Producció<span class="sr-only">(current)</span></li>
<li>Menu2</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown"><a href="#" class="dropdown-toggle"
data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION['username'] ?></a>
<ul class="dropdown-menu" role="menu">
<li><span class="glyphicon glyphicon-wrench"></span> preferències</li>
<li><span class="glyphicon glyphicon-lock"></span> canviar password</li>
<li class="divider"></li>
<li><span class="glyphicon glyphicon-log-out"></span> log out</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<!-- TABLE -->
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1 class="text-center">Miquel Alimentació</h1>
</div>
</div>
<hr>
</div>
<div class="container">
<div class="row text-center">
<div class="col-md-6 col-md-offset-3"><h3>Edició 12</h3></div>
</div>
<hr>
<div class="row">
<?php
// Conexió a la base de dades
include("connect.php");
$conn = Conectarse("localhost", "5432", "dbname", "dbuser", "dbpass");
//query
$query = "SELECT * FROM produccion.ma_origen ORDER BY id_articulo ASC";
$result = pg_query($conn, $query);
//se despliega el resultado
echo "<table id='tableprod'
data-toggle='table'
data-toolbar='#toolbar'
data-show-refresh='true'
data-show-toggle='true'
data-sort-name='name'
data-sort-order='desc'
data-show-columns='true'
data-pagination='true'
data-search='true'
data-click-to-select='true'>";
echo "<thead class='thead-inverse'>";
echo "<tr>";
echo "<th data id='seleccion' data-switchable='false' data-checkbox='true'></th>";
echo "<th data id='pagina' data-sortable='true'>pagina</th>";
echo "<th data id='codigo' data-sortable='true' data-switchable='false'>codigo</th>";
echo "<th data id='descripcion' data-sortable='true' data-switchable='false'>descripcion</th>";
echo "<th data id='pvp-cat' data-sortable='true'>pvp-cat</th>";
echo "<th data id='pvp-lev' data-sortable='true'>pvp-lev</th>";
echo "<th data id='pvp-and' data-sortable='true'>pvp-and</th>";
echo "<th data id='pvp-cen' data-sortable='true'>pvp-cen</th>";
echo "<th data id='pvp-nor' data-sortable='true'>pvp-nor</th>";
echo "<th data id='pvp-vas' data-sortable='true'>pvp-vas</th>";
echo "<th data id='fecha-mod' data-sortable='true'>fecha-mod</th>";
echo "<th data id='user' data-sortable='true' data-visible='false'>user</th>";
echo "<th data id='edit' data-sortable='false' data-switchable='false'>edit</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = pg_fetch_row($result)){
echo "<tr>";
echo "<td></td>";
echo "<td>$row[2]></td>";
echo "<td>$row[3]</td>";
echo "<td>$row[4]</td>";
echo "<td>$row[5]</td>";
echo "<td>$row[6]</td>";
echo "<td>$row[7]></td>";
echo "<td>$row[8]</td>";
echo "<td>$row[9]</td>";
echo "<td>$row[10]</td>";
echo "<td>$row[11]</td>";
echo "<td>$row[12]</td>";
echo "<td><p data-placement='top' data-toggle='tooltip' title='Edit'><button class='btn btn-primary btn-xs' data-title='Edit' data-toggle='modal' data-target='#edit' ><span class='glyphicon glyphicon-pencil'></span></button></p></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
</div>
</div>
<hr>
<div class="row">
<div class="text-center col-md-6 col-md-offset-3">
<p>Copyright © 2016 · All Rights Reserved · <a href="http://www.addvantage.es/" >http://www.addvantage.es</a></p>
</div>
</div>
<hr>
</div>
<!-- MODAL MENU -->
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">Editar registre</h4>
</div>
<div class="modal-body">
<div class="form-group">
<input class="form-control " type="text" placeholder="Pàgina">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="Codi">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="Descripció">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="pvp-cat">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="pvp-lev">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="pvp-and">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="pvp-cen">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="pvp-nor">
</div>
<div class="form-group">
<input class="form-control " type="text" placeholder="pvp-vas">
</div>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-warning btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> Update</button>
</div>
</div>
</div>
</div>
<!-- SESSION PHP ERROR -->
<?php
} else{
?><p>La sesión no está activa, por favor ingrese aquí</p>
<?php
}?>
</body>
</html>
I use php to connect to database and add data into the table. My idea is from a edit button can modify this fields from a modal window. After that I would like to update database.
I'm not sure if this is the best way, I haven't a experience programming from web environment.
Please Could you help me to modify this data-fields from windows modal?
Thanks!
The way to try to do is correct. What you have to do is on clicking Edit link find the closest tr and find all the td that tr contain. Read td one by one the assign it to the text box.
Below is the code:
$('.edit').click(function(){
var $row = $(this).closest("tr"), $tds = $row.find("td"); //This will all the tds we need.
$.each($tds, function() {
$('#txtbox').val($(this).text()); //textbox in the modal window
});
});
The above code will fill all the values from the row to modal window after that you can modify and submit the form.
First step - identify row somehow. I'm working under assumption that $row[0] is the id of that row in the database. If it isn't change the code accordingly.
index.php
while ($row = pg_fetch_row($result)){
echo "<tr id="{$row[0]}">"; // assign id that corresponds to database id to each row
echo "<td></td>";
echo "<td class="pagina">$row[2]></td>";
echo "<td class="codigo">$row[3]</td>";
echo "<td class="descripcion">$row[4]</td>";
echo "<td class="pvp-cat">$row[5]</td>";
echo "<td class="pvp-lev">$row[6]</td>";
echo "<td class="pvp-and">$row[7]></td>";
echo "<td class="pvp-cen">$row[8]</td>";
echo "<td class="pvp-nor">$row[9]</td>";
echo "<td class="pvp-vas">$row[10]</td>";
echo "<td class="fecha-mod">$row[11]</td>";
echo "<td class="user">$row[12]</td>";
echo "<td>
<p data-placement='top' data-toggle='tooltip' title='Edit'>
<button class='edit' class='btn btn-primary btn-xs' data-title='Edit' data-toggle='modal' data-target='#edit'>
<span class='glyphicon glyphicon-pencil'></span>
</button>
</p>
</td>";
echo "</tr>";
}
Second, set jquery click event to copy values from rows and fill the modal input fields with correct values:
JQUERY
$('.edit').click(function(){
var row = $(this).closest("tr"), // edit button is in the same row as data you want to change
tds = row.find("td"); // get all table cells in that row
$.each(tds, function(index) {
if( $.inArray(index, [0, 10, 11, 12]) ) { // indexes of cells not to be used when getting data from table cells to edit
return; // skip to next loop iteration if one of these indexes
}
var input_name = $(this).attr("class"); // get name of cell we are evaluating (pagina, codigo, descripcion etc)
$([name='"' + input_name + '"']).val($(this).text()); //input name in the modal window
});
});
I've changed the modal to reflect changes in code above.
MODAL
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
<h4 class="modal-title custom_align" id="Heading">Editar registre</h4>
</div>
<form action="/store.php">
<div class="modal-body">
<input type="hidden" name="id" type="text"> <!-- hidden input for id -->
<div class="form-group">
<input class="form-control" name="pagina" type="text" placeholder="Pàgina">
</div>
<div class="form-group">
<input class="form-control" name="codigo" type="text" placeholder="Codi">
</div>
<div class="form-group">
<input class="form-control" name="descripcion" type="text" placeholder="Descripció">
</div>
<div class="form-group">
<input class="form-control" name="pvp-cat" type="text" placeholder="pvp-cat">
</div>
<div class="form-group">
<input class="form-control" name="pvp-lev" type="text" placeholder="pvp-lev">
</div>
<div class="form-group">
<input class="form-control" name="pvp-and" type="text" placeholder="pvp-and">
</div>
<div class="form-group">
<input class="form-control" name="pvp-cen" type="text" placeholder="pvp-cen">
</div>
<div class="form-group">
<input class="form-control" name="pvp-nor" type="text" placeholder="pvp-nor">
</div>
<div class="form-group">
<input class="form-control" name="pvp-vas" type="text" placeholder="pvp-vas">
</div>
</div>
<div class="modal-footer ">
<input type="submit" class="btn btn-warning btn-lg" style="width: 100%;" value="Update">
</div>
</form>
</div>
</div>
</div>
File for storing edited values to the database:
store.php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id = $_POST['id'];
$pagina = $_POST['pagina'];
$codigo = $_POST['codigo'];
$descripcion = $_POST['descripcion'];
$pvp-cat = $_POST['pvp-cat'];
$pvp-lev = $_POST['pvp-lev'];
$pvp-and = $_POST['pvp-and'];
$pvp-cen = $_POST['pvp-cen'];
$pvp-nor = $_POST['pvp-nor'];
$pvp-vas = $_POST['pvp-vas'];
$sql = "UPDATE produccion.ma_origen SET pagina='{$pagina}',codigo='{$codigo}',descripcion='{$descripcion}',
pvp-cat='{$pvp-cat}', pvp-lev='{$pvp-lev}',pvp-and='{$pvp-and}',
pvp-cen='{$pvp-cen}',pvp-nor='{$pvp-nor}',pvp-vas='{$pvp-vas}'
WHERE id={$id}";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
Since this was a lot of code to change and I don't have the time and all the data to test this properly you'll have to do it, but this is one of the ways you could solve your problem. Hope it helps.

how to show sorting for jquery datatable in DESC

I'm displaying data from database in JQuery data tables.I want to display latest inserted record in top. My SQL query is working fine,but however JQuery data tables sorting is not happening.....so I want to sort data DESC order for data tables. Where I have to change in plugins? I'm using the following plugins:
jquery.dataTables.js, jquery.resizable.js, jquery.sortable.js
This is my code:
Appointments.php
<head>
<!--<meta http-equiv="refresh" content="30" />
--></head>
<?php
include_once 'config.php';
$menu_name = 'patient';
$_SESSION['menu']= $menu_name;
if(isset($_REQUEST['id']) && $_REQUEST['id']!='')
{
if(isset($_REQUEST['act']) && $_REQUEST['act']!='')
{
if($_REQUEST['act']=='r')
{
$id = $_REQUEST['id'];
$deleteCondition = " id_patient='".$id."'";
$deleted=$db->delete('patients',$deleteCondition);
header("Location: appointments.php?m=r");
}
}
}
/*echo $query="SELECT p.*,u.fileno FROM patients AS p,users AS u WHERE p.status='a' AND p.users_id_user=u.id_user order by p.id_patient DESC";*/
/*echo $query="select p.*,u.fileno,s.title from patients as p INNER JOIN users as u ON p.users_id_user=u.id_user
left join services as s ON p.service_id=s.id_service where p.status='a'"; */
echo $query="select p.*,u.fileno,s.title from patients as p INNER JOIN users as u ON p.users_id_user=u.id_user
left join photos as s ON p.service_id=s.id_photo where p.status='a' order by p.id_patient DESC";
$resultPatient=$db->select($query);
//$qry="select p.*,s.title from patients as p,service as s innser join services on p.service_id=s.id_service";
//$resultPatient=$db->select($qry);
$msgConfirmDelete ="Do you really want to delete this Patient ?";
include_once 'header.php';
?>
<script type="text/javascript">
var msgDelete = '<?php echo $msgConfirmDelete; ?>';
function confirmDelete()
{
if (confirm(msgDelete))
{
return true;
}
else
{
return false;
}
}
</script>
<!-- Sidebar begins -->
<div id="sidebar">
<!-- Left Main menu begins -->
<?php include_once 'menu.php'; ?>
<!-- Left Main menu ends -->
<!-- Secondary nav -->
<div class="secNav">
<div class="secWrapper">
<!--div class="secTop">
</div-->
<!--div class="divider"></div-->
<div id="general">
<div id="general" style="display: block;" class="active">
<ul class="subNav">
<li><span class="icos-images2"></span>Add Appointment</li>
<li class="activeli"><span class="icos-images2"></span>View/Edit Appointments</li>
<li><span class="icos-images2"></span>Appointments History</li>
<li><span class="icos-images2"></span>View/Edit Reminder Settings</li>
<li><span class="icos-images2"></span>Add Reminder Settings</li>
<li><span class="icos-images2"></span>View/Edit Medicine Reminder Settings</li>
<li><span class="icos-images2"></span>Add Medicine Reminder Settings</li>
</ul>
</div>
</div>
</div>
<div class="clear"></div>
</div>
</div>
<!-- Sidebar ends -->
<!-- Content begins -->
<div id="content">
<div class="contentTop">
<span class="pageTitle"><span class="icon-screen"></span>View Appointments</span>
<div class="clear"></div>
</div>
<!-- Breadcrumbs line -->
<div class="breadLine">
<div class="bc">
<ul id="breadcrumbs" class="breadcrumbs">
<li>Dashboard</li>
<li>Appointments</li>
<li class="current">View Appointments</li>
</ul>
</div>
</div>
<!-- Main content -->
<div class="wrapper">
<div class="fluid">
<?php if(isset($_GET['m'])&&$_GET['m']=="a"){?>
<div class="nNote nSuccess">
<p>Appointment Added Successfully !</p>
</div>
<?php }
if(isset($_GET['m'])&&$_GET['m']=="d"){?>
<div class="nNote nSuccess">
<p>Appointment Status Changed Successfully !</p>
</div>
<?php }
if(isset($_GET['m'])&&$_GET['m']=="r"){?>
<div class="nNote nSuccess">
<p>Appointment Deleted Successfully !</p>
</div>
<?php }
if(isset($_GET['m'])&&$_GET['m']=="re"){?>
<div class="nNote nSuccess">
<p>Reminder Sent Successfully !</p>
</div>
<?php }
if(isset($_GET['m'])&&$_GET['m']=="u"){?>
<div class="nNote nSuccess">
<p>Appointment Updated Successfully !</p>
</div>
<?php } ?>
<div class="widget">
<div class="whead"><h6>View Appointment Information</h6><div class="clear"></div></div>
<div id="dyn2" class="shownpars">
<a class="tOptions act" title="Options"><img src="images/icons/options.png" alt="" /></a>
<table cellpadding="0" cellspacing="0" border="0" class="dTable">
<thead>
<tr>
<th>Sl. No.<span class="sorting" style="display: block;"></span></th>
<!--<th>Sl.No</th>-->
<th>Date</th>
<th>File No</th>
<th>Name</th>
<th>Email</th>
<th>Age</th>
<th>Gender</th>
<th>Service</th>
<th>Phone</th>
<th>Time</th>
<th width="80">Action</th>
</tr>
</thead>
<tbody>
<?php
$sl=0;
$req_date='';
if($resultPatient && count($resultPatient)>0)
foreach($resultPatient as $patient)
{
$sl+=1;
$req_date=date('d F Y', strtotime($patient['date']));
?>
<tr class="gradeX">
<td class="center"><?php echo $sl;?></td>
<td class="center"><?php echo $req_date;?></td>
<td class="center"><?php echo $patient['fileno'];?></td>
<td class="center"><?php echo $patient['name'];?></td>
<td class="center"><?php echo $patient['email'];?></td>
<td class="center"><?php echo $patient['age'];?></td>
<td class="center"><?php echo strtoupper($patient['gender']);?></td>
<td class="center"><?php echo $patient['title'];?></td>
<td class="center"><?php echo $patient['phone'];?></td>
<td class="center"><?php echo $patient['time'];?></td>
<td class="tableActs">
<span class="iconb" data-icon=""></span>
<a onclick="return confirmDelete();" href="appointments.php?id=<?php echo $patient['id_patient'];?>&act=r" class="tablectrl_small bDefault tipS" title="Delete"><span class="iconb" data-icon=""></span></a>
<span class="iconb" data-icon=""></span>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<!-- Main content ends -->
</div>
<!-- Content ends -->
</body>
</html>
You can do this in following way. may be it helps you.
$(document).ready(function() { var oTable = $('#example').dataTable(); oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );} );
You can read more options here and click on "fnSort" for sorting details.

Progress bar php and mysql

I need to build progress bar next to the names of people showing how many costumers each people have working for him. When you see the code you will understand my problem. I dont know how to build this.
Just before end of body, before script tags i have progress bar and var that show's names from db. I need to show that names and beside them progress bar with percentage of costumers.
this are my tables
<?php
if (isset($_GET['poslovni_korisnici'])) {
$active1 = 'class="active"';
}
else {
$active1 = '';
}
if(isset($_GET['korisnici'])) {
$active2 = 'class="active"';
}
else {
$active2 = '';
}
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'root';
/*** mysql password ***/
$password = '';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=zadatak1", $username, $password);
/*** echo a message saying we have connected ***/
/**echo 'Connected to database';**/
}
catch(PDOException $e)
{
echo $e->getMessage();
}
echo'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Statistika</title>
<!-- Bootstrap -->
<link href="css/bootstrap.css" rel="stylesheet">
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css">
<!-- jQuery -->
<script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">POSLOVNA STATISTIKA</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li ' . $active1 . '>Poslovni korisnici <span class="sr-only">(current)</span></li>
<li ' . $active2 . '>Korisnici</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>';
switch (isset($_GET)) {
case isset($_GET['poslovni_korisnici']):
echo'
<h1>Poslovni korisnici</h1>
<button type="button" class="btn btn-default btn-sm">Unos</button>
</br>
</br>';
echo'
<table id="table_id" class="display">
<thead>
<tr>
<th>Partner id</th>
<th>Partner name</th>
<th>Partner street</th>
<th>Partner zip</th>
<th>Partner city</th>
<th>Partner country</th>
</tr>
</thead>
<tbody>';
$sql = "SELECT * FROM poslovni_partneri";
foreach ($dbh->query($sql) as $row)
{
echo'
<tr>
<td>'.$row['Partner_id'].'</td>
<td>'.$row['Partner_name'].'</td>
<td>'.$row['Partner_street'].'</td>
<td>'.$row['Partner_zip'].'</td>
<td>'.$row['Partner_city'].'</td>
<td>'.$row['Partner_country'].'</td>
</tr>';
}
echo'
</tbody>
</table>';
break;
case (isset($_GET['korisnici'])):
echo'
<h1>Korisnici</h1>
<button type="button" class="btn btn-default btn-sm">Unos</button>
</br>
</br>
<table id="table_id" class="display">
<thead>
<tr>
<th>User id</th>
<th>Partner ID</th>
<th>User name</th>
<th>User department</th>
<th>User email</th>
<th>User phone</th>
<th>User mobile</th>
</tr>
</thead>
<tbody>';
$sql = "SELECT * FROM korisnici
INNER JOIN poslovni_partneri
ON korisnici.Partner_id=poslovni_partneri.Partner_id";
foreach ($dbh->query($sql) as $row)
{
echo'
<tr>
<td>'.$row['User_id'].'</td>
<td>'.$row['Partner_id'].'</td>
<td>'.$row['User_name'].'</td>
<td>'.$row['User_department'].'</td>
<td>'.$row['User_email'].'</td>
<td>'.$row['User_phone'].'</td>
<td>'.$row['User_mobile'].'</td>
</tr>';
}
echo'
</tbody>
</table>';
break;
default:
$sql = "SELECT Partner_name FROM poslovni_partneri";
$del = $dbh->prepare('SELECT * FROM poslovni_partneri');
$del->execute();
$count = $del->rowCount();
$del = $dbh->prepare('SELECT * FROM korisnici');
$del->execute();
$count2 = $del->rowCount();
echo '<div class="panel panel-primary">
<div class="panel-heading">Popis poslovnih partnera</div>
<div class="panel-body">
<button class="btn btn-primary" type="button">
Broj poslovnih korisnika <span class="badge">'.$count.'</span>
</button>
</br>
</br>
<button class="btn btn-primary" type="button">
Broj korisnika <span class="badge">'.$count2.'</span>
</button>
</br>
</br>
<div class="panel panel-primary">
<div class="panel-heading">Popis poslovnih partnera <p class="text-center">Ukupni udio</p></div>
<ul class="list-group">';
foreach ($dbh->query($sql) as $row)
{
echo'
<li class="list-group-item list-group-item-info">
<span class="badge">144</span>
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:%">
<span class="sr-only">40% Complete (success)</span>
</div>
</div>
<h4 class="names">'.$row['Partner_name'].'</h4>
</li>';
}
echo'
</ul>
</div>
</div>';
break;
}
echo'
<script>
$(document).ready( function () {
$("#table_id").DataTable();
} );
</script>
<!-- jQuery (necessary for Bootstraps JavaScript plugins) -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
</html>';
?>
You should first get count of customers of each people. Now on basis of number of customers build your progress bar.
Step 1.
Get count of customers.
//add your logic here
$customer_count=<for_exampe_its_20>
Step 2.
Now on basis of count display your progress bar
<div class="progress">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<? php echo ($customer_count) ?>" aria-valuemin="0" aria-valuemax="100" style="width: <? php echo ($customer_count) ?>%">
<span class="sr-only"><? php echo ($customer_count) ?>customers(success)</span>
</div>
</div>

Categories