First, I would have a database set up like shown below
CREATE TABLE addresses (
id int(11) NOT NULL auto_increment,
aptcomplex varchar(200) default NULL,
streetaddr varchar(200) default NULL,
city varchar(55) default NULL,
state char(2) default NULL,
zip varchar(200) default NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
Then of course, you'll need a form, a way to process that form, and a way to display all of your info. I've set up an example php page that would probably do the trick for ya; you would most definitely need to modify a couple of things.. but it's a working example.
Here she is, excuse the sloppiness 😛
<?php
/*
* Basic Form
*
*/
$self=$_SERVER['PHP_SELF'];
echo
"<form action=\"$self\" method=\"POST\">
<input type=\"text\" name=\"aptcomplex\"> Apartment Complex<br />
<input type=\"text\" name=\"streetaddr\"> Street Address<br />
<input type=\"text\" name=\"city\"> City<br />
<input type=\"text\" name=\"state\"> State<br />
<input type=\"text\" name=\"zip\"> Zip Code<br />
<BUTTON NAME=\"postedInfo\" value=\"Add Your Location\" TYPE=\"submit\">Add Me</BUTTON>
</form>";
/*
* NOTE:
* <BUTTON> tag is valid HTML 4 But i think it only works
* in IE 4+ (last i knew anyway.)
*
*/
/*
* Database Configuration:
*
* $server = server db is on
* $user = authorized db user
* $pass = authorized db user's pass
* $database = database to connect to
*
*/
$server = "localhost";
$user = "root";
$pass = "rootpass";
$database = "locations";
/*
* Here is some code that connects to the
* database server, selects the database
* and if need be, inserts user posted
* information into the database.
*
*/
$dbQuery = @mysql_connect($server,$user,$pass) or die ("Cannot connect to $server " . mysql_error() . "");
mysql_select_db ($database) or die ("Cannot connect to $database " . mysql_error() . "");
if($_POST['aptcomplex'] && $_POST['zip']) {
$sql = "INSERT INTO `addresses` ( `aptcomplex` , `streetaddr` , `city` , `state` , `zip` )
VALUES ('".$_POST['aptcomplex']."', '".$_POST['streetaddr']."', '".$_POST['city']."', '".$_POST['state']."', '".$_POST['zip']."')";
@mysql_query($sql) or die ("Error Updating Database " . mysql_error() . "");
} // end IF statement
elseif(!$_POST['aptcomplex'] && !$_POST['zip']) {
echo "Want to add your Location to our database? Fill out this form!";
} // end ELSEIF statement
echo "<br /><br />Current Locations In Our Database";
/*
* Here we're setting up a table to display
* our users addresses to our users.
*
*/
$tableTop =
"<table width=\"100%\" border=\"1\" cellspacing=\"1\" cellpadding=\"1\">
<tr>
<td>ID</td>
<td>ApartMents</td>
<td>Street Address</td>
<td>City</td>
<td>State</td>
<td>Zip</td>
</tr>";
echo "$tableTop";
/*
* The following code will grab ALL
* information out of the table `addresses`
* Below, we count how many rows of info
* there are to show. If none, we'll tell
* our users that.
*
*/
$locationQuery = "SELECT * FROM `addresses` ORDER BY id DESC";
$locationResult = mysql_query($locationQuery);
if (! $locationResult ) {
echo "An Error has occured " . mysql_error(); die();
} // end IF statement
$rowcount = mysql_num_rows($locationResult);
if($rowcount == "0") {
echo
"<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>";
die(" There are no addresses in our database at this time. ");
} // end IF statement
while ( $r = mysql_fetch_array($locationResult) ) {
/*
* Setting up our row data as variables
* to make them easier to display
*
*/
$id=$r['id'];
$aptcomplex=$r['aptcomplex'];
$streetaddr=$r['streetaddr'];
$city=$r['city'];
$state=$r['state'];
$zip=$r['zip'];
$displayInfo =
"<tr>
<td>$id</td>
<td>$aptcomplex</td>
<td>$streetaddr</td>
<td>$city</td>
<td>$state</td>
<td>$zip</td>
</tr>";
/*
* Here we'll display an HTML table
* with all of our users information
* neatly organized. This can be done
* in other ways, but this I think was
* the easiest way for an example.
*
*/
echo "$displayInfo";
} // End While Loop
echo "</table>";
?>
Hopefully that will give you an idea of how you can loop through your users addresses & display the results the way you want.