简体   繁体   English

检索存在特定user_id的所有行的数据?

[英]Retrieving data all rows where specific user_id is present?

I am working on a user profile page, and I have made it to where a user can post text and that will be uploaded to the "posts" database. 我正在用户配置文件页面上工作,并且已经到达用户可以在其中发布文本的位置,该文​​本将被上传到“ posts”数据库。 That all works fine. 一切正常。 But now I want to make it to where if a user goes to a users profile, it will echo out all their user posts. 但是现在我想让用户进入用户个人资料的位置,它将回显所有用户的帖子。 The database is laid out this way: 数据库的布局方式如下:

post_id user_id content post_id user_id content

And I want to make it to where when a user lands on a user's page it grabs their $user_id and then forms a mysql_query and then echos out all of their posts that are present in the users database. 我想使其到达用户登陆用户页面的位置时,它抓住他们的$ user_id,然后形成mysql_query,然后回显出users数据库中存在的所有帖子。 What would be the best way to do this? 最好的方法是什么? Thanks 谢谢

So far I have tried this: mysql_result("SELECT * FROM posts WHERE user_id = $user_id"); 到目前为止,我已经尝试过: mysql_result("SELECT * FROM posts WHERE user_id = $user_id");

You are doing right thing. 你在做正确的事。

You have to just fetch all the data using the while loop. 您只需要使用while循环获取所有数据。

like. 喜欢。

$res=mysql_query("SELECT * FORM posts WHERE user_id=$user_id");

while($row=mysql_fetch_assoc($res))
{

echo $row['post_id'];
}

You got my point? 你明白我的意思吗?

 // execute the query
$stmt = mysql_query("SELECT * FROM posts WHERE user_id ='".$user_id."'");

then fetch using different php functions used to fetch data and display.. 然后使用用于获取数据和显示的不同PHP函数进行获取。

while($row = mysql_fetch_array($stmt)){
         echo $row['db_column_field'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM