$page = isset($_POST['page']) ? (int)$_POST['page'] : 1;
$perPage = isset($_POST['per-page']) && $_POST['per-page'] <= 50 ? (int)$_POST['per-page'] : 4;
$start = ($page > 1) ? ($page * $perPage) - $perPage : 0;
$econ = $db->prepare("
SELECT SQL_CALC_FOUND_ROWS admin.admin_id, ads.adCost, ads.adList, img_upload.img_path, address.address_id,
img_upload.img_id, ads.ad_id, img_upload.id, ads.adName
FROM admin
INNER JOIN ads
ON ads.ad_id=admin.ad_id
INNER JOIN address
ON address.address_id=admin.ad_id
LEFT JOIN img_upload
ON ads.ad_id = img_upload.img_id
WHERE ads.adCost ='economy' AND ads.adList = 5
LIMIT {$start}, {$perPage}
");
$econ->execute();
$econ = $econ->fetchAll(PDO::FETCH_ASSOC);
$total = $db->query("SELECT FOUND_ROWS() as total")->fetch()['total'];
$pages = ceil($total / $perPage);
<div id = "adminWrapper">
<p><h3>Premium requests </h3>
Example do not use this </p>
<?php foreach($minutes as $minute): ?>
<ul class="prem">
<li><form method="POST" action ="">
admin: <input type="text" name="premList" value="<?php echo $minute['admin_id']; ?>" readonly>
<input type="text" name="adListing" value="<?php echo $minute['id']; ?>" readonly>
<input type="text" name="imdId" value="<?php echo $minute['img_id']; ?>" readonly>
<input type="text" name="addressId" value="<?php echo $minute['address_id']; ?>" readonly>
<p>Ad cost: <?php echo $minute['adCost']; ?></p>
<p>Ad name: <?php echo $minute['adName']; ?></p>
<img src="<?php echo $minute['img_path']; ?>">
<input type ="submit" name="accept" value ="Accept">
<input type ="submit" name="reject" value ="Reject">
<form></li>
</ul>
<?php endforeach;?>
<div class ="pagecounter">
<?php for($x = 1; $x <= $pages; $x++): ?>
<a href="?page=<?php echo $x;?>&per-page=<?php echo $perPage; ?>"><?php echo $x;?></a>
<?php endfor ?>
</div>
</div>
try{
$db = new PDO("mysql:host=localhost;dbname=serverside", 'root', '');
$db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
echo $e->getMessage();
die();
}
if(isset($_POST['accept']))
{
$id = $_POST['premList'];
$id = $_POST['premList'];
$grouplisting = 3;
$idA = $_POST['addressId'];
$sql = "UPDATE ads
SET adList = $grouplisting
WHERE ad_id = $id;
DELETE FROM admin
WHERE ad_id = $idA;
";
$q = $db->prepare($sql);
$q->execute(array($id));
Redirect::to('admin.php');
}
if(isset($_POST['reject']))
{
$imgId = $_POST['imdId'];
$id = $_POST['premList'];
$idA = $_POST['addressId'];
$sql = "
DELETE FROM admin
WHERE ad_id = $id;
DELETE FROM img_upload
WHERE img_id = $imgId;
DELETE FROM ads
WHERE img_id = $imgId;
DELETE FROM address
WHERE address_id = $idA;
";
$q = $db->prepare($sql);
$q->execute(array($id));
Redirect::to('admin.php');
}
Basically I'm createing forms dynamically, each form has two buttons, each form should select the id required and delete the information related, however it's always deleteing the last one on the list rather than the one selected to be deleted or accepted.