Jump to content

Recommended Posts

let me just start off by saying i'm new to the php world but i'm trying to learn...

 

Ok I have a forum set up and i'm doing a query to get the username from my database to show who put the last post up and author. that works fine, BUT!!  it repeats the posts using every user i have in the database.haha.  obviously i have to correspond an id with username. but my question is how do i set it up so that the username who posted the message shows up instead of all my usernames in the database. below is the query i'm using...

 

$query  = "SELECT username FROM users";

$result = mysql_query($query);

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

    echo "{$row['username']}";

       

}

Link to comment
https://forums.phpfreaks.com/topic/137884-solved-forum-problem/
Share on other sites

In the post table you would need another field called AUTHOR_ID or just AUTHOR. Then you can change your query and add a WHERE clause to limit the results.

 

SELECT * FROM users WHERE username='$post_author'

 

So you would need to get all the post data, then perform another query. Or you can merge it, but if your new then don't worry about combining them.

Link to comment
https://forums.phpfreaks.com/topic/137884-solved-forum-problem/#findComment-720964
Share on other sites

ok, i understand the code that you gave and how you explained it so i know how to retrieve it.

 

but my next question is this...

on the reply page i have a comment box set up so that the user can input text for their post. now how would i say that the text was written by the username and store it on the database? then, on the message page i can get retrieve that information (which is the code projectfear helped me with) saying username posted this at such and such time.

 

let me know if you would like to see anymore code.

Link to comment
https://forums.phpfreaks.com/topic/137884-solved-forum-problem/#findComment-721072
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.