With the screenshot and the code below I am trying to get the ‘Delete Button’ to only show to the owner of the wall post. I am logged in as Michael Grigsby and as you can tell from the screenshot that the first wall post is hiding the ‘Delete Button’ but the rest are showing even when it comes to the Mike Wyatt post which I should not have ownership of.
I cannot figure out why this is being caused. I have two possibilities; either I have to loop through the wall posts in jQuery, or my SQL statement is not written right. Any ideas as to why this is acting this way?

PHP and jQuery Code:
<?php $this->load->helper('date');
$userid = $this->session->userdata('userid');
$query = $this->db->query("SELECT * FROM churchMembers WHERE cMuserId = '{$userid}'");
$row = $query->row();
if ($query->num_rows() != 0) {
$membersChurchId = $row->cMchurchId;
$query2 = $this->db->query("SELECT wp.idwallPosts, wp.entryData, wp.entryCreationDateTime, u.firstname, u.lastname, u.userid, u.defaultImgURI FROM users u
INNER JOIN wallPosts wp ON wp.postingUserid = u.userid
WHERE wp.wpChurchId = '{$membersChurchId}' ORDER BY wp.idwallPosts DESC LIMIT 200");
foreach ($query2->result() as $row) { ?>
<?php // the following php is the bootstrapper for the wall
if ($userid != $row->userid) { ?>
<script type="text/javascript">
$(document).ready(function() {
$("#delPost").remove();
});
</script>
<?php } ?>
I’m looking at this:
…and thinking that you probably have
id="delPost"on every item. A common misunderstanding aboutidattributes is that you can re-use them, but you can’t. There can only be one element per page withid="delPost"(validating your HTML would reveal the error).Anyways, your script is only reading the first one, as demonstrated by this demo. Each id must be unique, you may want to switch to
classinstead and rethink your logic, but that doesn’t make too much sense anyways because in that loop, as soon as one element is hidden they all would be because your selector is not very specific (applies to every element that matches your selector, looping/repeating that script is redundant).There are many ways to approach this but here’s what I suggest: Instead of hiding or removing them with javascript, just don’t output them at all with your PHP code.