Nov 8, 2009

How To: Display A Members/user List. - With PHP, Mysql, and HTML.

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

How To: Display A Members/user List. - With PHP, Mysql, and HTML.

Archimedes
Alright, some of you might want to display your User's or Members on your site.

Notes:
1.This is to fit in with Feelay's register and Log-in scripts you can find in the tutorial section.
2.I made this to show the members of my site who is a member and what their ID is.



First off, we must set up a connection to our MySQL Database.
CODE
<?php
$con = mysql_connect("localhost","database_username","database_username_password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

What it does:
1.It is starting a PHP document.
2.Next it sets up a connection to the database with the members table.
3.Change 'database_username' to your database username.
4.Change 'database_username_password' to your username's password.

Next, we select the database the information is stored at using the 'mysql_select_db() function.
CODE
mysql_select_db("userbase_name", $con);

What it does:
1.All it is doing is selecting a database using the connection in the first part of code.

For the next part, we will be selecting the table in which the members info is stored at, whereas the table is named 'members'.
And you want to order them by ID.
CODE
$result = mysql_query("SELECT * FROM members ORDER BY ID");

What it does:
1.The '$result', is just a variable, so you don't have to type the function again.
2.It is selecting everything '*', from the table members and ordering it by the user's ID.

For the third part, we will be creating a HTML table to display the user information.
CODE
echo "<table border='0'>
<tr>
<th>UserName</th>
<th>ID</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['UserName'] . "</td>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

What it does:
1.You can can change the '0' in the <table border=''> tag to anything you chose.
2.The '<th>User Name</th>'&'<th>ID</th>' tags are the top of the table.
3.The 'while() function is creating an array, whereas '$row' is a variable to shorten your work, instead of typing the mysql_fetch_array() function out again.
4.The 'echo "<td>" . $row['UserName'] . "</td>";' & ' echo "<td>" . $row['ID'] . "</td>";' is just selecting the info from the table to be displayed, whereas the user/members name is stored in the column 'UserName' and the ID is stored under 'ID'.

Ending your document.
CODE
mysql_close($con);
?>

What it does:
1.It is closing the connection we made in the first part of this tutorial.
2.It is closing the <?php tag in the first part of code of this tutorial.

The Output
User Name ID
User1 1
User2 2
User3 3
User4 4
etc. etc.


That's it!
Any questions, feel free to ask.
This is my first tutorial on Astahost forums.

 

 

 


Comment/Reply (w/o sign-up)

yordan
Nice tutorial, Archimedes. I appreciate the way you use simple words in order to explain rather complicated things (using php to make queries into the database and displaying the results on the screen). Lucky strike for a first tuto, I hope that you will continue this way.
Regards
Yordan

Comment/Reply (w/o sign-up)

Archimedes
Thank you, Yordan, I plan to have many more tutorials in the future! xD

Comment/Reply (w/o sign-up)

Feelay
lol xD this is too basic tongue.gif I didn't understand because it was sooo basic tongue.gif
haha tongue.gif almost kidding tongue.gif this is very basic ^.^ haha, making it fit with my login/register scripts biggrin.gif Cool biggrin.gif

Comment/Reply (w/o sign-up)

(G)Jason
Great Guide
How To: Display A Members/user List.

I have tryingfor 3 days to find a way to display only certain fields in my Joomla User database as and address book. I had already modified the registration script and the database itself to include phone numbers and such, but did not know enough about php/mysql to display them as a list, while excluding other information in the table.Your guide worked perfectly. Thank you!!

-reply by Jason

 


Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : , display, members, user, list, php, mysql, html,

  1. Js/php/mysql Timer
    (2)
  2. Creating A Content Managing System
    Using MySQL (15)
    This tutorial is for beginners that know some php and know the basics of MySQL. I will tell you how
    to make a simple Content Managing System. A Content Managing System is a way of editing and adding
    your content using your browser, so you dont have to go trough ftp all the time. This CMS uses
    MySQL databases. So what we need to do is to create a database. Well go through this step by step to
    make it as easy as posible: 1. Go in to your cPanel and select phpMyAdmin. 2. Write the name of
    your database in the input box under the text: Create new database. This database ....
  3. Rapid HTML code generation using simple PHP
    avoid those repetative boring tasks.... (8)
    I don't know about the rest of you, but I love writting scripts but hate WRITTING scripts. For
    example, how many times do you think you have typed the following. Example #1: CODE
    Select fields are worse, especially if you write clean code like I do with indents and seperate
    lines for each tag. Example #2: CODE     Apples     Oranges     Grapes    
    Peaches Having been writting HTML for 10 years now, so I look for as many shortcuts as
    possible. Now I let PHP write all of the repetitive HTML and I just fill in the blanks. From ....
  4. How To Create A PHP Based Hit Counter
    With MySQL (2)
    websaint recently posted a PHP hit counter using a flat-file to store information. This is a guide
    a wrote a little while ago - it was for another web site, but I'll post it here as well.
    ----------------------------------------------------------------------------------- First and
    foremost, you need to create a new table. You can use a whole new database if you want (and assuming
    you have one free), but it's a bit of a waste. For this guide, our table will be called
    'hits', and will contain two fields - 'unique' and 'total'. The first ....

    1. Looking for , display, members, user, list, php, mysql, html,

See Also,

*SIMILAR VIDEOS*
Searching Video's for , display, members, user, list, php, mysql, html,
advertisement



How To: Display A Members/user List. - With PHP, Mysql, and HTML.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com