Hello Every One i have small problem i will upload multiple images single input file and database store with comma i will stored but i have problem is remove the uploaded images selected and remove the image when we click the image above delete icon that only image deleted
My Code for Retrieve the Multiple images
<div class="panel-body">
<div class="table-responsive">
<table id="dataTableExample1" class="table table-striped table-bordered">
<thead>
<tr>
<th>S.No</th>
<th>Gallery Images</th>
<th>Gallery Name</th>
<th>Operation</th>
</tr>
</thead>
<tbody>
<?php
extract($_REQUEST);
$sql="SELECT * FROM `smw_gallery`";
$result = $conn->query($sql);
$count=$result->num_rows;
if ($count > 0) {
$i=1;
while ($row = $result->fetch_object()) {
$primages = $row->smw_gallery_images;
$imgp = explode(",", $primages);
$realPath = '../assets/images/gallery/';
?>
<tr>
<td style="width:10%"><?=$i;?></td>
<td style="width:50%">
<?php foreach($imgp as $img)
{
echo '<a class="example-image-link" href="#" data-lightbox="example-set" data-title="Click the right half of the image to move forward."><img class="example-image" src="'.$realPath.'/'.$img.'" alt="" height="80" width="80" style="margin: 10px;"/></a>';
} ?>
</td>
<td style="width:10%">
<?php
$limit = 30;
$td_title1 = $row->smw_gallery_name;
if (strlen($td_title1) > $limit)
$td_title1 = substr($td_title1, 0, strrpos(substr($td_title1, 0, $limit), ' '))."...";
echo $td_title1;
?></td>
<td style="width:20%">
<center>
<i class="fa fa-pencil-square-o btn btn-warning" aria-hidden="true"></i>
</center>
</td>
</tr>
<?php $i++; } } ?>
</tbody>
</table>
</div>
</div>
the above code Output look like this
each image i will place delete button and hole gallery delete button
how to made to single image delete button and remove that image only remain will be as it is display
You can do it with small help of jquery, ajax and mysql.
On click delete icon you have to make one ajax request with image name and id parameters. Update image name in database using below query. On success ajax response you can remove that image block using jquery.
Html code for image. Just a sample line.
DeleteIcon
Jquery Code
$(document).on('click', '.delete-image', function(){
var $this = $(this);
var imagname = $(this).data('name');
$.post("delete_image.php",
name: imagname,
id: 1
},
function(data, status){
$this.closest(tr).remove(); //Write your remove code for single image
});
})
I have write code is look like this :
<img class="btn-delete" id="photo-<?=$photo_index_key;?>" data-id="<?=$photo_index_key;?>" data-name="<?=$photo_name;?>" style="margin: 3px 1px 74px -17px; cursor: pointer;" src="../assets/images/closes.png";>
each one of indexkey value can taken in jquery var $imageId = $(this).attr('id');
<script>
$(document).on('click', '.btn-delete', function(){
var imageId = $(this).attr('data-id');
var imageName = $(this).attr('data-name');
var dataString = {id:imageId, name: imageName}
$.ajax({
type: "POST",
url: "remove.php",
data: dataString,
cache: false,
success: function(html){
$('#photo'+imageId).remove(); // you can write your logic
}
});
});
</script>
remove.php
//get ajax data:
$id = $POST['id'];
$name = $POST['name'];
UPDATE smw_gallery
SET `smw_gallery_images` = REPLACE(`smw_gallery_images`, $name,'')
WHERE `id` = $id;
What if you do it in appearance.
That is, you can define the array by indexes
<div class="panel-body">
<div class="table-responsive">
<table id="dataTableExample1" class="table table-striped table-bordered">
<thead>
<tr>
<th>S.No</th>
<th>Gallery Images</th>
<th>Gallery Name</th>
<th>Operation</th>
</tr>
</thead>
<tbody>
<?php
extract($_REQUEST);
$sql = "SELECT * FROM `smw_gallery`";
$result = $conn->query($sql);
$count = $result->num_rows;
if ($count > 0) {
$i = 1;
while ($row = $result->fetch_object()) {
$primages = $row->smw_gallery_images;
$imgp = explode(",", $primages);
$realPath = '../assets/images/gallery/';
?>
<tr>
<td style="width:10%"><?= $i; ?></td>
<td style="width:50%">
<?php foreach ($imgp as $photo_index_key => $img) {
echo '<a class="example-image-link" href="#" data-lightbox="example-set" data-title="Click the right half of the image to move forward.">
<img class="example-image" src="' . $realPath . '/' . $img . '" alt="" height="80" width="80" style="margin: 10px;"/>
</a>';
echo "<a href='".$realPath . "/remove.php?smw_gallery_id=" . $row->id . "&photo_index_key=" . $photo_index_key . "'></a>";
} ?>
</td>
<td style="width:10%">
<?php
$limit = 30;
$td_title1 = $row->smw_gallery_name;
if (strlen($td_title1) > $limit)
$td_title1 = substr($td_title1, 0, strrpos(substr($td_title1, 0, $limit), ' ')) . "...";
echo $td_title1;
?></td>
<td style="width:20%">
<div style="text-align: center;">
<a href="gallery-edit.php?edit=<?= $row->smw_gallery_id; ?>" title="Edit"><i
class="fa fa-pencil-square-o btn btn-warning" aria-hidden="true"></i></a>
</div>
</td>
</tr>
<?php $i++;
}
} ?>
</tbody>
</table>
</div>
I don't know English. This was done via google translate
remove.php
<?php
if (!empty($_GET['smw_gallery_id'] && !empty($_GET['photo_index_key']))) {
$sql = sprintf("SELECT `smw_gallery_images` FROM `smw_gallery` WHERE `id` = %d", $_GET['smw_gallery_id']);
$result = $conn->query($sql);
$result->fetch_assoc();
if (!is_null($result) && is_array($result)) {
while ($row = $result->fetch_assoc()) {
$smw_gallery_images = explode(",", $row['smw_gallery_images']);
$new_smw_gallery_images = array_splice($smw_gallery_images, $_GET['photo_index_key'], 1);
$new_smw_gallery_images = implode(',', $new_smw_gallery_images);
$updateSql = sprintf("UPDATE smw_gallery SET `smw_gallery_images` = %s WHERE `id` = %d", $new_smw_gallery_images, $_GET['smw_gallery_id']);
$conn->query($updateSql);
}
}
}
Related
I am trying to do a pagination for category result page which is listing articles with ajax.
I use where clause and need to pass article id to the ajax page.
My codes : ajax.php
include_once '../db.php';
include_once '../class/Articles.php';
$ArticleHandler = new Articles($pdo);
if (!(isset($_GET['pageNumber']))) {
$pageNumber = 1;
} else {
$pageNumber = $_GET['pageNumber'];
}
$perPageCount = 5;
$catid = $_POST['article_id'];
$sql = "SELECT * FROM posts WHERE pcat = ?";
$posts = $ArticleHandler->getPosts($sql, [$catid])->fetchAll();
if ($posts !== '0') {
$rowCount = $ArticleHandler->getPosts("SELECT count(*) FROM posts")->fetchColumn();
}
$pagesCount = ceil($rowCount/$perPageCount);
$lowerLimit = ($pageNumber - 1) * $perPageCount;
$sql = "SELECT * FROM posts WHERE pcat = :pcat ORDER BY pid DESC LIMIT :offset, :limit";
$results = $ArticleHandler->getPosts($sql, array(':pcat'=>$catid, ':offset'=>$lowerLimit, ':limit'=>$perPageCount))->fetchAll();
?>
<table class="table table-hover table-responsive">
<tr>
<th align="center">Name</th>
<th align="center">Experience<br>(in years)
</th>
<th align="center">Subject</th>
</tr>
<?php foreach ($results as $data) { ?>
<tr>
<td align="left"><?php echo $data['ptitle'] ?></td>
</tr>
<?php
}
?>
</table>
<div style="height: 30px;"></div>
<table width="50%" align="center">
<tr>
<td valign="top" align="left"><?php echo $catid; ?></td>
<td valign="top" align="center">
<?php
for ($i = 1; $i <= $pagesCount; $i ++) {
if ($i == $pageNumber) {
?>
<?php echo $i ?>
<?php
} else {
?>
<a href="javascript:void(0);" class="pages"
onclick="showRecords('<?php echo $perPageCount; ?>', '<?php echo $i; ?>');"><?php echo $i ?></a>
<?php
}
}
?>
</td>
<td align="right" valign="top">
Page <?php echo $pageNumber; ?> of <?php echo $pagesCount; ?>
</td>
</tr>
</table>
And index.php
<div id="results"></div>
<div id="loader"></div>
Ajax codes :
function showRecords(perPageCount, pageNumber) {
$.ajax({
type: "GET",
url: "modules/ajax.php",
data: "pageNumber=" + pageNumber,
cache: false,
beforeSend: function() {
$('#loader').html('<img src="loader.png" alt="reload" width="20" height="20" style="margin-top:10px;">');
},
success: function(html) {
$("#results").html(html);
$('#loader').html('');
}
});
}
$(document).ready(function() {
showRecords(10, 1);
});
My tries : I've added a div with artcile id to index.php and used attr to pass it to ajax but couldn't pass it to the page.
Try passing the article id along with pageNumber that you are passing in GET request.
data: {pageNumber : YOUR_PAGE_NUMBER, articleId: ARTICLE_ID}
Do not forget to pass the articleId as 3rd parameter to the function.
I am using load more button to load content from the database of specific id on the same web page. Here is the code:
<div class="postList col-lg-12">
<legend><h1 style="color:#298208;">Savings Bucks Details</h1> </legend>
<?php
$busi_id = mysqli_real_escape_string($conn, $_SESSION['busi_id']);
if (isset($busi_id)) {
$query = "SELECT * FROM savingsbucks_business WHERE busi_id='$busi_id' ORDER BY sbb_id DESC LIMIT 2";
$result = mysqli_query($conn, $query) or die('Query failed: ' . mysqli_error($conn));
$numrows_savingsbucks = mysqli_num_rows($result);
if ($numrows_savingsbucks == '0') {
echo "<p style='text-align:center; color:#ff4400; margin-top:40px;'>No Data available!</p>";
} else {
?>
<div class="table-responsive">
<table border="1" class="table table-bordered">
<thead>
<th class="consumer_point_text">Shop ID</th>
<th class="consumer_point_text">SenderID</th>
<th class="consumer_point_text">Busi ID</th>
<th class="consumer_point_text">Customer Type</th>
<th class="consumer_point_text">Customer Name</th>
<th class="consumer_point_text">Customer Email</th>
<th class="consumer_point_text">Customer Phone</th>
<th class="consumer_point_text">Two</th>
<th class="consumer_point_text">Five</th>
<th class="consumer_point_text">Ten</th>
<th class="consumer_point_text">Twenty</th>
<th class="consumer_point_text">Fifty</th>
<th class="consumer_point_text">Hundred</th>
<th class="consumer_point_text">Five Hundred</th>
<th class="consumer_point_text">Total Savings Bucks</th>
</thead>
<?php if($numrows_savingsbucks > 0){
while ($row = mysqli_fetch_array($result)) {
$sbb_id = $row['sbb_id'];
$sender_id = $row['sender_id'];
$busi_id = $row['busi_id'];
$type = $row['type'];
$consu_name = $row['consu_name'];
$consu_email = $row['consu_email'];
$consu_phone = $row['consu_phone'];
$two = $row['two'];
$five = $row['five'];
$ten = $row['ten'];
$twenty = $row['twenty'];
$fifty = $row['fifty'];
$hundred = $row['hundred'];
$five_hundred = $row['five_hundred'];
$total_two += $two;
$total_five += $five;
$total_ten += $ten;
$total_twenty += $twenty;
$total_fifty += $fifty;
$total_hundred += $hundred;
$total_five_hundred += $five_hundred;
$total_bucks = $two+$five+$ten+$twenty+$fifty+$hundred+$five_hundred;
$grand_total += $total_bucks;
?>
<tr>
<td class="consumer_point_text"><?=$sbb_id?></td>
<td class="consumer_point_text"><?=$sender_id?></td>
<td class="consumer_point_text"><?=$busi_id?></td>
<td class="consumer_point_text" style="text-transform:capitalize;"><?=$type?></td>
<td class="consumer_point_text"><?=$consu_name?></td>
<td class="consumer_point_text"><?=$consu_email?></td>
<td class="consumer_point_text"><?=$consu_phone?></td>
<td class="consumer_point_text"><?=$two?></td>
<td class="consumer_point_text"><?=$five?></td>
<td class="consumer_point_text"><?=$ten?></td>
<td class="consumer_point_text"><?=$twenty?></td>
<td class="consumer_point_text"><?=$fifty?></td>
<td class="consumer_point_text"><?=$hundred?></td>
<td class="consumer_point_text"><?=$five_hundred?></td>
<td class="consumer_point_text"><?=$total_bucks?></td>
</tr>
<?php } ?>
</table>
<div class="show_more_main" sbb_id="show_more_main<?php echo $sbb_id; ?>">
<span sbb_id="<?php echo $sbb_id; ?>" class="show_more" title="Load more posts">Load more</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script
<script src="http://demos.codexworld.com/includes/js/bootstrap.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','.show_more',function(){
var ID = $(this).attr('sbb_id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type:'POST',
url:'ajax_more_business_shop.php',
data:'sbb_id='+ID,
success:function(html){
$('#show_more_main'+ID).remove();
$('.postList').append(html);
}
});
});
});
</script>
<?php } ?>
</div> <!-- ./col-lg-12 -->
<?php } }?>
On this page its displaying 2 results which have common busi_id (WHERE busi_id=$busi_id), when I click on load more button, its displaying others content too which don't have same "busi_id" as on this page showing first 2 results.
Here is ajax page:
ajax_more_business_shop.php :
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
if(!empty($_POST["sbb_id"])) {
require_once ('admin/includes/config.php');
$query = "SELECT COUNT(*) as num_rows FROM savingsbucks_business WHERE sbb_id < ".$_POST['sbb_id']." ORDER BY sbb_id DESC";
$result = mysqli_query ($conn, $query);
$row = mysqli_fetch_assoc($result);
$totalRowCount = $row['num_rows'];
$busi_id = $row['busi_id'];
$showLimit = 2;
$query = "SELECT * FROM savingsbucks_business WHERE sbb_id < ".$_POST['sbb_id']." ORDER BY sbb_id DESC LIMIT $showLimit";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
$rowcount=mysqli_num_rows($result);
?>
<table border="1" class="table table-bordered">
<?php
if ($rowcount > '0') {
while($row = mysqli_fetch_assoc($result))
{
$sbb_id = $row['sbb_id'];
$sender_id = $row['sender_id'];
$busi_id = $row['busi_id'];
$type = $row['type'];
$consu_name = $row['consu_name'];
$consu_email = $row['consu_email'];
$consu_phone = $row['consu_phone'];
$two = $row['two'];
$five = $row['five'];
$ten = $row['ten'];
$twenty = $row['twenty'];
$fifty = $row['fifty'];
$hundred = $row['hundred'];
$five_hundred = $row['five_hundred'];
$total_two += $two;
$total_five += $five;
$total_ten += $ten;
$total_twenty += $twenty;
$total_fifty += $fifty;
$total_hundred += $hundred;
$total_five_hundred += $five_hundred;
$total_bucks = $two+$five+$ten+$twenty+$fifty+$hundred+$five_hundred;
$grand_total += $total_bucks;
?>
<tr>
<td class="consumer_point_text"><?=$sbb_id?></td>
<td class="consumer_point_text"><?=$sender_id?></td>
<td class="consumer_point_text"><?=$busi_id?></td>
<td class="consumer_point_text"><?=$type?></td>
<td class="consumer_point_text"><?=$consu_name?></td>
<td class="consumer_point_text"><?=$consu_email?></td>
<td class="consumer_point_text"><?=$consu_phone?></td>
<td class="consumer_point_text"><?=$two?></td>
<td class="consumer_point_text"><?=$five?></td>
<td class="consumer_point_text"><?=$ten?></td>
<td class="consumer_point_text"><?=$twenty?></td>
<td class="consumer_point_text"><?=$fifty?></td>
<td class="consumer_point_text"><?=$hundred?></td>
<td class="consumer_point_text"><?=$five_hundred?></td>
<td class="consumer_point_text"><?=$total_bucks?></td>
</tr>
<?php }
?>
</table>
<?php if($totalRowCount > $showLimit){ ?>
<div class="show_more_main" sbb_id="show_more_main<?php echo $sbb_id; ?>">
<span sbb_id="<?php echo $sbb_id; ?>" class="show_more" title="Load more posts">Show more</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading...</span></span>
</div>
<?php } ?>
<?php
}
}
?>
I want, when i click "load more button", It must show/load 2 more row of content where busi_id will be common, I mean if busi_id=69, it should show/load only 2 more content/result from database which have busi_id 69, not other data with different busi_id.
I tried to explain,
Thank you.
I have just passed the "busi_id" to Ajax page... with load more button..
<div class="show_more_main" ds_id="show_more_main<?php echo $ds_id; ?>">
<span ds_id="<?php echo $ds_id; ?>" busi_id="<?php echo $busi_id; ?>" class="show_more" title="Load more posts">Load more</span>
<span class="" style="display: none;"><span class="loding_txt">Loading...</span></span>
</div>
And..
<script type="text/javascript">
$(document).ready(function(){
$(document).on('click','.show_more',function(){
var ID = $(this).attr('ds_id');
var Busi_id = $(this).attr('busi_id');
$('.show_more').hide();
$('.loding').show();
$.ajax({
type:'POST',
url:'ajax_more_consumer_shop.php',
data: {
'ds_id': ID,
'busi_id': Busi_id
},
success:function(html){
$('#show_more_main'+ID).remove();
$('.postList').append(html);
}
});
});
});
on ajax_more_business_shop.php....
$query = "SELECT COUNT(*) as num_rows FROM savingsbucks_business WHERE ds_id < ".$_POST['ds_id']." AND busi_id=".$_POST["busi_id"]." ORDER BY ds_id DESC";
$result = mysqli_query ($conn, $query);
$row = mysqli_fetch_assoc($result);
$totalRowCount = $row['num_rows'];
$showLimit = 2;
$query = "SELECT * FROM savingsbucks_business WHERE ds_id < ".$_POST['ds_id']." AND busi_id=".$_POST["busi_id"]." ORDER BY ds_id DESC LIMIT $showLimit";
$result = mysqli_query ($conn, $query);
$rowcount=mysqli_num_rows($result);
Modified the query.. and get the desired output.
Thanks!
I have a table named tbl_video that consist of two fields (video_id, video_title What I want to add a load more button using Ajax JQuery like social networking sites .I am able to get the first two records but when I try second time nothing happens. I dont get any errors .What am i doing wrong .
this my index.php file I create table structure here and then fetch two records.And get the second record's id value and send it to the more.php file
<body>
<table class="table table-bordered" id="load_data_table">
<thead>
<tr>
<td width="15%">Video Id</td>
<td>Video Title</td>
</tr>
</thead>
<?php
while ($row = mysqli_fetch_array($result)) {
$video_id = $row['video_id']; ?>
<tr>
<td><?php echo $row['video_id']; ?></td>
<td><?php echo $row['video_title']; ?></td>
</tr>
<?php
}
?>
<tr id="remove_row"><td><button type="button" id="more" class="btn btn-success form-control"
data-id="<?php echo $video_id; ?>">More</button></td></tr>
</table>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#more').click(function(){
var id=$(this).data("id");
$.ajax({
url:"more.php",
data:{id:id},
method:"post",
success:function(data){
if(data!=''){
$('#load_data_table').append(data);
$('#remove_row').remove();
}
else{
$('#more').html("No Data");
}
}
and this the more.php file.I think it is self explanatory
$id = $_POST['id'];
$output = '';
$db = mysqli_connect('localhost', 'root', '', 'testing');
$data = mysqli_query($db, "select * from tbl_video where video_id >{$id} limit 2");
if (mysqli_num_rows($data)) {
while ($row = mysqli_fetch_array($data)) {
$output .= '
<tbody>
<tr>
<td>'.$row['video_id'].'</td>
<td>'.$row['video_title'].'</td>
</tr>
';
}
$output .= '
<tr id="remove_row"><td><button type="button" id="more" class="btn btn-success form-control"
data-id="'.$row['video_id'].'">More</button></td></tr></tbody>
';
echo $output;
}
any help would be appriciated.
When you add a new row and there is a new button for More
It has the same id as the original button so there is a conflict there
also the javascript needs to be initiliazed something like this
PHP:
$output .= '<tr id="remove_row"><td><button type="button" class="more btn btn-success form-control" data-id="'.$row['video_id'].'">More</button></td></tr></tbody>';
Javascript:
<script>
function moreButton() {
$('.more').click(function(){
var id=$(this).data("id");
$.ajax({
url:"more.php",
data:{id:id},
method:"post",
success:function(data){
if(data!=''){
$('#load_data_table').append(data);
$('#remove_row').remove();
moreButton();
}
else{
$('.more:last').html("No Data");
}
}
});
}
$(document).ready(function(){
moreButton();
});
Don't forget to remove the id of the more button to a class with .more
I have a page that allows for multiple record deletes using checkboxes and all works fine.
However, each record may have an image associated with it stored in a folder that would also need to be deleted but I have no idea how to achieve this even though I've searched Stackoverflow and Google.
How do I delete the record(s) from the MySQL database and the image(s) associated with it from the folder?
What I have so far is:
The code that deletes the records:
if ( isset( $_POST[ 'chk_id' ] ) ) {
$arr = $_POST[ 'chk_id' ];
foreach ( $arr as $id ) {
#mysqli_query( $KCC, "DELETE FROM pageContent WHERE contentID = " . $id );
}
$msg = "Page(s) Successfully Deleted!";
header( "Location: delete-familyservices.php?msg=$msg" );
}
The form that selects the records to delete:
<form name="deleteRecord" id="deleteRecord" method="post" action="delete-familyservices.php">
<?php if (isset($_GET['msg'])) { ?>
<p class="alert alert-success">
<?php echo $_GET['msg']; ?>
</p>
<?php } ?>
<table width="100%" class="table table-striped table-bordered table-responsive">
<tr>
<th>Page Title</th>
<th>Page Text</th>
<th>Page Image</th>
<th>Delete</th>
</tr>
<?php do { ?>
<tr>
<td width="30%" style="vertical-align: middle">
<h4 style="text-align: left">
<?php echo $row_rsContent['contentTitle']; ?>
</h4>
</td>
<td width="45%" style="vertical-align: middle">
<?php echo limit_words($row_rsContent['contentData'], 10); ?> ...</td>
<td align="center" style="vertical-align: middle">
<?php if (($row_rsContent['contentImage']) != null) { ?>
<img src="../images/<?php echo $row_rsContent['contentImage']; ?>" class="img-responsive">
<?php } else { ?> No Image
<?php } ?>
</td>
<td width="5%" align="center" style="vertical-align: middle"><input type="checkbox" name="chk_id" id="chk_id" class="checkbox" value="<?php echo $row_rsContent['contentID']; ?>">
</td>
</tr>
<?php } while ($row_rsContent = mysqli_fetch_assoc($rsContent)); ?>
</table>
<p> </p>
<div class="form-group" style="text-align: center">
<button type="submit" name="submit" id="submit" class="btn btn-success btn-lg butt">Delete Selected Page(s)</button>
<button class="btn btn-danger btn-lg butt" type="reset">Cancel Deletion(s)</button>
</div>
</form>
The final piece of code, which is a confirmation script:
<script type="text/javascript">
$( document ).ready( function () {
$( '#deleteRecord' ).submit( function ( e ) {
if ( !confirm( "Delete the Selected Page(s)?\nThis cannot be undone." ) ) {
e.preventDefault();
}
} );
} );
</script>
I've seen the unlink() function mentioned but I don't know if this is what to use or have any idea how to incorporate it into the existing code if it is.
you'll have to use the path of the image which is stored on you database like so :
unlink(' the link of the images which is fetched from db'); // correct
don't forget to check for image existence file_exists() //
Got this from another site and a bit of trial and error.
if($_POST) {
$arr = isset($_POST['chk_id']) ? $_POST['chk_id'] : false;
if (is_array($arr)) {
$filter = implode(',', $arr);
$query = "SELECT *filename* FROM *table* WHERE *uniqueField* IN ({$filter})";
$result = mysqli_query(*$con*, $query);
while ($row = mysqli_fetch_object($result)) {
$pathToImages = "*path/to/images*";
{
unlink("{$pathToImages}/{$row->contentImage}");
}
}
// DELETE CAN BE DONE IN ONE STATEMENT
$query = "DELETE FROM *table* WHERE *uniqueField* IN ({$filter})";
mysqli_query(*$con*, $query);
$msg = "Page(s) Successfully Deleted!";
header("Location: *your-page.php*?msg=$msg");
}
}
Thanks to everyone who contributed.
Hope this is of some help to others.
Here is the description of my issue:
I have a db connection here:
$host = 'some host credentials';
$dbh = 'My database';
Here is my statement:
$qry = "SELECT some_data FROM some_table LIMIT 1000";
$result = some code here;
Here is my while loop:
echo '<table class="table table-striped table-hover table-bordered" id="example">
<thead>
<tr class="test">
<th style="border: 1px solid #333;">PRODUCTPRICE</th>
<th>PRODUCTNAME</th>
<th>PRODUCTCODE</th>
<th>PRODUCTSALE</th>
<th>PRODUCTPRICE</th>
</tr>
</thead>
<tbody>';
while ($row = mysql_fetch_assoc($result)){
$PRODUCTID = intval($row["PRODUCTID"]);
$PRODUCTNAME = $row["PRODUCTNAME_1"];
$PRODUCTCODE = $row["PRODUCTCODE"];
$PRODUCTSALE = $row["PRODUCTSALE_"];
$PRODUCTPRICE = $row["PRODUCTPRICE"];
echo '<tr class="odd gradeX">
<td>'.$PRODUCTID.'</td>
<td>'.$PRODUCTNAME.'</td>
<td>'.$PRODUCTCODE.'</td>
<td class="center">'.$PRODUCTSALE.'</td>
<td class="center">'.$PRODUCTPRICE.'</td>
</tr>';
}
echo '</tbody>
</table></div>
</div>
</body>
</html>';
I want to make a loader before this content table display because there are more than 50,000 products. Something kind of processing or a circle showing that a content is loading, just a simple one, maybe jQuery or ajax. I have tried many tutorials till now but no success.
here is a scheme for that :
<div id="content"></div>
$.ajax({
url : 'the-above-script.php',
beforeSend : function() {
$("#content").html('<img src="ajax-icon-from-www.ajaxload.info">');
},
success : function(html) {
$("#content").html(html);
}
});