通过屏幕截图和下面的代码,我试图让“删除按钮”只显示给墙帖的所有者。我以 Michael Grigsby 的身份登录,您可以从屏幕截图中看出,第一个墙帖隐藏了“删除按钮”,但即使涉及到我不应该拥有的 Mike Wyatt 帖子,其余的也会显示。
我无法弄清楚为什么会这样。我有两种可能;要么我必须在 jQuery 中遍历墙上的帖子,要么我的 SQL 语句写得不正确。关于为什么这样做的任何想法?
PHP 和 jQuery 代码:
<?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 } ?>