Database:
For the purposes of this post we will do a simple one table database. The database holds a user_id and a name.
So one record would be like this user_id = 1 name= Brent.
So now that we have a database set up I am going to focus on the just getting the data out, if you want me to explain how to connect to the database and all that jazz just let me know and I will write it up.
PHP:
First, in order to get the data we have to write the query:
$sql = "select * from user";
The $sql variable now holds our query.
To execute the query you use mysql_query();
$results = mysql_query($sql);
This runs our $sql query and puts the results in a mysql resource called $results.
Now, we need to get out all that data with a loop. I use a while loop most of the time because it seems to work just fine for me. Right now the $results variable is a mysql resource so we need to make it an array. So all in one step I am going to put the data into an array and use the while loop to pull it out and display it on the page.
while($row = mysql_fetch_array($results)){
$name = $row['name'];
$user_id = $row['user_id'];
echo "Name is ".$name." User Id is ".$user_id."Put a line Break here!"
}
This first grabs the mysql resource into an array called $row then I grab the name and user_id out of the array and echo them out to the page.
It is a simple as that!
Please email me with any questions!