I'm creating a medium post approval system in "Gambiarra", what I did is, when the user posts, it gets value '0' in the 'Status' table in the database.
So I have a restricted page for the site's adm, on this page I have a loop that displays the posts with Status 0 (Posts not yet approved), in this loop I also have a button in each post that when clicking will change the table Status from '0' to '1'. The problem is that when I click, it modifies all posts and not just what I'm clicking. I need something that just identifies that post.For this I used a javascript script, the sequence of everything goes on:
The loop on the restricted page:
<?php while ($row = $sql->fetch(PDO::FETCH_ASSOC)) { ?>
<div class="post">
<h2 id="titulo"><?php echo $row['titulo']; ?></h2>
<p>POSTAGEM</p>
<button type="button" name="button" onclick="myAjax()" >aprovar</button>
</div>
<?php } ?>
JavaScript on the restricted page:
<script type="text/javascript">
function myAjax() {
$.ajax({
type: "POST",
url: '_controller/approvajax.php',
data:{id:$("#ajax").val()},
success:function(html) {
alert(html);
}
});
}
</script>
The ajax file:
<?php
include_once('../_inc/conexao.inc.php');
$up = $conexao->query("UPDATE vagas SET status = 1");
$up->execute();
?>
Any advice to just select that post?