So you want to pull information out of a MySQL table, eh?
First off, you obviously need a database server to work with, along with a database. I'm sure you know this, but sometimes it doesn't hurt to state the obvious.
First, you'll want to define your database information in a file called config.php or something similiar.
<?php
/* MySQL Information */
$server = "localhost"; // location of mysql server
$user = "db_userName"; // database user name
$password = "usersPass"; // database user's password
$db = "db_toConnectTo"; // name of database
?>
Now, you'll want to connect to the database
<!-- Starting an HTML Table -->
<table width="100%" border="0">
<?php
include("config.php"); // name of file w/ MySQL Information in it
$dbQuery = mysql_connect($server,$user,$password);
mysql_select_db ($db) or die ("Cannot connect to database");
/*
*
*You should now be connected to the database server,
*and selected the proper database you want to withdraw
*information from.
*
*/
$query = "SELECT * FROM dataBaseTable ORDER BY id DESC";
/*
*
* This is saying select everything from the database $db in
* the table 'dataBaseTable' and it will order everything from
* newest to oldest. The rest should be pretty well self-
* explanitory. If not, do some more reading
*
*/
$result = mysql_query($query); // Add error checking
$rowcount = mysql_num_rows($result); // counting rows
while($r=mysql_fetch_array($result))
{
/* This bit sets our data from each row as variables, to make it easier to display */
$firstName=$r['firstname'];
$lastName=$r['lastname'];
$address1=$r['address1'];
$address2=$r['address2'];
/*
*
* For sake of an example, say in your database you're storing
* peoples names, first & last, along w/their address. So you'll
* have table names like "firstname", "lastname" and "address"
* etc. Now, what the above is doing, is making it really easy to
* tell the code to look in a certain row by just using a variable.
* To access 'firstname', you would just need to type echo "$firstName";
* etc etc...
*
*/
echo "<tr><td>$firstName</tr></td>\n
<tr><td>$lastName</tr></td>\n
<tr><td>$address1</tr></td>\n
<tr><td>$address2</tr></td>";
} // end While Loop
/*
*
* Now, you'll be shown an HTML table including the
* first name, last name, address1 & 2 for EVERY
* entry in your database.
*
*/
?>
</table>
Maybe I wasn't perfectly clear, but I think if you're interested in getting started w/mysql and php the above should be a great starting point and hopefully it helped.