/
var
/
www
/
html
/
stengineers
/
admin
/
Upload FileeE
HOME
<?php header('Access-Control-Allow-Origin: *'); require_once('dbconnection.php'); $bmenu_active = "active"; include 'header.php'; ?> <!-- Begin Page Content --> <div class="container-fluid"> <!-- Page Heading --> <h1 class="h3 mb-2 text-gray-800">Blog List</h1> <p> <a href="blog-add.php" class="btn btn-success btn-icon-split"> <span class="icon text-white-50"> <i class="fas fa-check"></i> </span> <span class="text">Add Blog</span> </a> </p> <!-- DataTales Example --> <div class="card shadow mb-4"> <div class="card-header py-3"> <!-- <h6 class="m-0 font-weight-bold text-primary">DataTables Example</h6> --> </div> <div class="card-body"> <div class="table-responsive"> <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0"> <thead> <tr> <th>Title</th> <th>Image</th> <th>Author</th> <th>Created at</th> <th>Status</th> <th>Action</th> </tr> </thead> <!-- <tfoot> <tr> <th>Title</th> <th>Image</th> <th>Created at</th> <th>Total Comments</th> <th>Status</th> <th>Approved</th> <th>Action</th> </tr> </tfoot> --> <tbody id="table_id"> <?php $s = "select * from blogs"; $res = mysqli_query($con, $s); $num = mysqli_num_rows($res); if ($num == 0) { echo '<tr> <td colspan="6">No Datas Found</td> </tr>'; } else { $sql = "SELECT id,title,id as blog_id, author, thump_image, status, DATE_FORMAT(created_at, '%d-%m-%Y') as created_at ,'0' as total_count,'0' as pending_count ,'0' as approved_count FROM blogs ORDER BY id DESC"; $selected = mysqli_query($con, $sql); while($row = mysqli_fetch_assoc($selected)) { $carr[] = $row; } for ($i=0; $i <count($carr) ; $i++) { $blog_id = $carr[$i]['blog_id']; // echo $url; $row1=mysqli_query($con,"select count(*) as pending from blog_comments as a where a.status='pending' and a.blog_id = '$blog_id'"); $row2=mysqli_fetch_array($row1); $carr[$i]['pending_count'] = $row2['pending']; $row3=mysqli_query($con,"select count(*) as total from blog_comments as a where a.blog_id = '$blog_id'"); $row4=mysqli_fetch_array($row3); $carr[$i]['total_count'] = $row4['total']; $row5=mysqli_query($con,"select count(*) as approved from blog_comments as a where a.status='approved' and a.blog_id = '$blog_id'"); $row6=mysqli_fetch_array($row5); $carr[$i]['approved_count'] = $row6['approved']; } for ($i=0; $i <count($carr) ; $i++) { $id = $carr[$i]['id']; $title = $carr[$i]['title']; $image = $carr[$i]['thump_image']; $author = $carr[$i]['author']; $blog_id = $carr[$i]['blog_id']; $created_at = $carr[$i]['created_at']; $status = $carr[$i]['status']; $pending_count = $carr[$i]['pending_count']; $approved_count = $carr[$i]['approved_count']; echo "<tr> <td>$title</td> <td><img src='$image' style='width:100px' /></td> <td>$author</td> <td>$created_at</td> <td>$status</td> <td style='white-space: nowrap;'> <a href='blog-edit.php?id=$id' class='btn btn-info btn-circle btn-sm'> <i class='fas fa-edit'></i> </a> <a class='btn btn-danger btn-circle btn-sm' onclick='deleteData($id)'> <i class='fas fa-trash'></i> </a> </td> </tr>"; } } ?> </tbody> </table> </div> </div> </div> </div> <!-- /.container-fluid --> <script type="text/javascript"> function refreshData(){ $("#table_id").load(window.location + " #table_id"); } function deleteData(id){ var id = id; var getData; if(confirm('Are you sure you want to delete?')) { $.ajax({ url: 'api/admin-blog.php', type: 'POST', data:{id:id,action:"deleteblog", referer:"ezioaws"}, success: function (response) { var data = JSON.parse(response); console.log(data); if (data.status == 'success') { alert("Deleted Successfully") window.location.href="blog.php"; } else { alert("Failed, Please try again later") } // refreshData(); } }); } } </script> <?php include 'footer.php'?>