PHP/MySQLi Creating a Forum - Part 17 - User List
Submitted by Yorkiebar on Sunday, January 26, 2014 - 22:46.
PHP/MySQLi Creating a Forum - Part 16 - Log In Requirement
Introduction:
This tutorial will be continuing my series of creating a forum in PHP/MySQLi/HTML. In this part I will be showing you how to add a user list to your forum to make it easier for users to find each other.
Pre-creation:
First you will need a host for your PHP, either a web host or localhost is fine but you will need PHP and MySQL(i) capabilities.
Also, this will not be covering creating users, or styling the pages. For the purpose of using the logged in users username, we will be using $_SESSION['username']; from my login script, you can find that tutorial on my profile page.
Obviously you will also need to go through all the previous parts of this tutorial series which can all be found on my profile tracking page.
members.php:
For the user list I am going to create a new page named members.php, I suggest you do the same.
members.php Editing:
Before we do anything, we need to carry over the session for the logged in users, and connect to our database...
As you can see, I am also making it a requirement for them to be logged in to an account before they can view other members within the user list.
Next we want to create a query to select all the user accounts from our users table...
Then we want to make sure there is at least one user account in our query results and if there is, create a variable named list which will be a container for an html table containing all of our users names...
Now we want to go through each user account and add their username as a new row in our list HTML table container. Each one will have a link to userPage.php?username= followed by their username...
We also finish off the HTML of our table in the variable list container.
So now we have all the information contained within a fairly nice table in our list variable container. We just need to output it to the browser frame...
Full Source:
Here is the full source of the members.php file. If you have any questions or suggestions feel free to contact me or reply to this thread!
- <?php
- }
- ?>
- $list = '<table><tbody>';
- }
- $list .= '<tr><td><a href="userPage.php?username='.$row["username"].'">'.$row["username"].'</a></td></tr>';
- }
- $list .= '</tbody></table>';
- <html>
- <head></head>
- <body>
- </body>
- </html>
- <html>
- <head></head>
- <body>
- </body>
- </html>
Add new comment
- 49 views