ryans18 Posted December 21, 2008 Share Posted December 21, 2008 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']}"; } Quote Link to comment https://forums.phpfreaks.com/topic/137884-solved-forum-problem/ Share on other sites More sharing options...
JasonLewis Posted December 21, 2008 Share Posted December 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137884-solved-forum-problem/#findComment-720964 Share on other sites More sharing options...
ryans18 Posted December 22, 2008 Author Share Posted December 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/137884-solved-forum-problem/#findComment-721072 Share on other sites More sharing options...
fenway Posted December 22, 2008 Share Posted December 22, 2008 Are you talking about writing the INSERT statment? Quote Link to comment https://forums.phpfreaks.com/topic/137884-solved-forum-problem/#findComment-721580 Share on other sites More sharing options...
ryans18 Posted December 23, 2008 Author Share Posted December 23, 2008 yeah i think so but thats ok i went with a different approach. but thanks anyways Quote Link to comment https://forums.phpfreaks.com/topic/137884-solved-forum-problem/#findComment-722007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.