Help me about using session username in json

Help me about using session username in json

jajuljajul Posts: 1Questions: 1Answers: 0

This code below just show the data when i login with the level superadmin or admin.
But when i login with the level user, the data just show the process loading.
I don't know where is the wrong of this code below:

```
<?php
session_start();
require_once "../../../config/fungsi/koneksi.php";
require_once "../../../config/fungsi/fungsi_indotgl.php";
$aksi="modul/mod_blog/aksi_blog.php";
$requestData= $_REQUEST;
$username = $_SESSION['namauser'];

$columns = array(
0 => 'id_blog',
1 => 'jdl_blog',
2 => 'nama_lengkap',
3 => 'nama_kategori',
4 => 'tanggal',
5 => 'aktif_blog'
);

// getting total number records without any search
if($_SESSION['leveluser']=='superadmin' OR $_SESSION['leveluser']=='admin'){
$sql = "SELECT id_blog, jdl_blog, judul_seo, nama_lengkap, nama_kategori, aktif_blog, username, gbr_blog, tanggal ";
$sql.=" FROM blog_view";
}else{
$sql = "SELECT id_blog, jdl_blog, judul_seo, nama_lengkap, nama_kategori, aktif_blog, username, gbr_blog, tanggal ";
$sql.=" FROM blog_view WHERE username = '".$_SESSION['username']."'";
}
$query = mysqli_query($db, $sql) or die("load-data.php: get InventoryItems");
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData;

if( !empty($requestData['search']['value']) ) {
$sql = "SELECT id_blog, jdl_blog, judul_seo, nama_lengkap, nama_kategori, aktif_blog, username, gbr_blog, tanggal ";
$sql.=" FROM blog_view";
$sql.=" WHERE jdl_blog LIKE '".$requestData['search']['value']."%' ";
$query=mysqli_query($db, $sql) or die("load-data.php: get PO");
$totalFiltered = mysqli_num_rows($query);
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
$query=mysqli_query($db, $sql) or die("load-data.php: get PO");
}else{
$sql = "SELECT id_blog, jdl_blog, judul_seo, nama_lengkap, nama_kategori, aktif_blog, username, gbr_blog, tanggal ";
$sql.=" FROM blog_view";
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
$query=mysqli_query($db, $sql) or die("load-data.php: get PO");
}

$data = array();
$no = 1;
while( $row=mysqli_fetch_array($query) ) {
$nestedData=array();
$nestedData[] = $no;
if($row['aktif_blog']=='Ya'){
$nestedData[] = '<a href="../berita/'.$row['id_blog'].'/'.$row['judul_seo'].'" target="_blank">'.$row['jdl_blog'].'</a>';
}else{
$nestedData[] = $row['jdl_blog'];
}
$nestedData[] = $row["nama_lengkap"];
$nestedData[] = $row["nama_kategori"];
$nestedData[] = tgl_indo($row["tanggal"]);
if($row['aktif_blog']=='Ya'){
$nestedData[] = '<a href="'.$aksi.'?module=blog&act=statusblokir&id='.abs((int)$row['id_blog']).'" class="btn btn-success btn-xs">Diterbitkan</a>';
}else{
$nestedData[] = '<a href="'.$aksi.'?module=blog&act=statusaktif&id='.abs((int)$row['id_blog']).'" class="btn btn-warning btn-xs">Draft</a>';
}
$nestedData[] = '

';
$data[] = $nestedData;
$no++;
}

$json_data = array(
"draw" => intval( $requestData['draw'] ),
"recordsTotal" => intval( $totalData ),
"recordsFiltered" => intval( $totalFiltered ),
"data" => $data
);

echo json_encode($json_data);

<?php > ``` ?>

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    I'm afraid I can't debug your PHP code for you, but I would suggest having a look at the server's error logs. It might indicate what the issue is.

    Allan

This discussion has been closed.