I know I am doing something wrong here but I couldn't figure out where ? Trying to display records and delete them by clicking on a Remove button, records get displayed but they are duplicates eventhough in my Table they are unique, here is my code:
// Fech files and display them in a Modal
if($_POST["action"] == "fetch_files")
{
$file_data = scandir($_POST["folder_name"]);
?>
<table class="table table-striped table-sm" cellspacing="0" width="100%">
<tr style="background-color:#FFC300">
<th style="text-align: left">Document Name</th>
<!-- <th style="text-align: center">Category</th> -->
<th style="text-align: right">Remove Document</th>
</tr>
<?php
foreach($file_data as $file)
{
$records = mysqli_query($conn,"select * from files"); // fetch data from database
while($data = mysqli_fetch_array($records))
{
if($file === '.' or $file === '..')
{
continue;
}
else
{
$path = $_POST["folder_name"] . '/' . $file;
?>
<tr>
<td data-folder_name="<?php echo $_POST["folder_name"]; ?>" data-file_name = "<?php echo $file; ?>" class="change_file_name"><?php echo $file; ?></td>
<td><a href="delete.php?id=<?php echo $data['id']; ?>" button name="remove_file" class="remove_file btn btn-danger btn-sm float-right" id="<?php echo $path; ?>">Remove</button></td>
</tr>
<?php
}
}
}
source https://stackoverflow.com/questions/70342639/getting-wrong-records-count-from-my-mysql-table
Comments
Post a Comment