简体   繁体   中英

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. 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

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. 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");

You are doing right thing.

You have to just fetch all the data using the while loop.

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..

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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