[英]When i use this php the results show all the table not the specific condition that table1.id = table2.id
|---------------------|------------------|
| User_id Primary | Email |
|---------------------|------------------|
| 1 | a@a.com |
|---------------------|------------------|
| 2 | b@b.com |
|---------------------|------------------|
|---------------------|------------------|
| Post_id Primary | User_id Foreign |
|---------------------|------------------|
| 1 | 1 |
|---------------------|------------------|
Here's the code 这是代码
$conn1 = @mysqli_connect('127.0.0.1','root','','signup');
$sql1 = "SELECT post_pic ,post_text FROM table2 INNER JOIN table1
ON (table2.User_id = table1.User_id) " ;
$result = mysqli_query($conn1, $sql1);
if(mysqli_num_rows($result)>0){
while ($row = mysqli_fetch_array($result)){
so when im logged in user id=2 user id=1 posts are shown 因此,当我登录时,用户ID = 2的用户ID = 1帖子显示
You need to specify the user id in your query, why you are getting images for user 1 is that your code at the moment runs as expected. 您需要在查询中指定用户ID,为什么要获得用户1的图像是因为您的代码目前正在按预期运行。
If you want to get data only for user1, you need to add a where clause specifying the user ID. 如果只想获取user1的数据,则需要添加where子句以指定用户ID。
Like so: 像这样:
//For Arguments Sake
$user_id = $_SESSION['loggedin_user_id'];
$sql1 = "SELECT post_pic ,post_text
FROM table2
INNER JOIN table1
ON (table2.id = table1.id)
WHERE table2.User_id = '$user_id'";
EDIT: Actually I just noticed that @04FS already mentioned it in a comment. 编辑:实际上我只是注意到@ 04FS已经在评论中提到了它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.