I want to ask,
I have two tables , users and posts with column field
users : user_id, name, email
posts : post_id, user_id, post_title
I want to display all posts from all users,
but I want only logged_in user session to have another two extra button while other public posts only have two button
p/s : I used email column field in users table as login $_SESSION.
<?php
global $connect;
global $user_id;
$sql_post = "SELECT * FROM posts";
$run_post = mysqli_query($connect, $sql_post);
if($run_post && mysqli_num_rows($run_post) > 0 )
{
while($row_post = mysqli_fetch_array($run_post))
{
$post_id = $row_post['post_id'];
$user_id = $row_post['user_id'];
$post_title = $row_post['post_title'];
$sql_user = "SELECT * FROM users WHERE user_id='$user_id'";
$run_user = mysqli_query($connect, $sql_user);
$check_user = mysqli_fetch_array($run_user);
$user_id = $check_user['user_id'];
$user_name = $check_user['name'];
$user_email = $check_user['email'];
$post_output = "<div id='posts_wrap'>
<p>$user_name</p>
<p>$user_email</p>
<p>$post_title</p>
<a href=''><button>Like</button></a>
<a href=''><button>Comment</button></a>
// i want these two button (Edit and Delete) only available to logged in user
<a href=''><button>Edit</button></a>
<a href=''><button>Delete</button></a>
</div>
";
echo $post_output;
}
mysqli_free_result($run_post);
}
else
{
echo "No post yet";
}
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…