<?php
# this include grabs 1 company from the database and displays it

# here we set up the fields we want to grab
$fields		= 'company_id, company_name, address1, address2, city, state_id, zip';
$fields		.= ', contact_name, contact_title, contact_email, url';
$fields		.= ', phone_area, phone_exchange, phone_digits, phone_extension';
$fields		.= ', fax_area, fax_exchange, fax_digits, fax_extension';

# basic form of grabbing rows from a DB
# ok, this is really dumb... I can't leave off the while-loop and echo just 1 row... argh!!!
$result = mysql_query("SELECT $fields FROM company where company_id = $company_id");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

  # column 1
  echo "<table border=1 width=\"100%\">\n<tr>\n<td valign=\"top\">\n";
  # if URL exists, print it as a link
  if ( !( $row["url"] == '' ) ) {
    echo "<a href=\"" . $row["url"] . "\">" . $row["company_name"] . "</a><br>";
  } else {
    echo $row["company_name"] . "<br>";
  }
  echo $row["address1"] . "<br>";
  # only echo address2 if it exists
  if ( !( $row["address2"] == '' ) ) {
    echo $row["address2"] . "<br>";
  }
  echo $row["city"] . ", ";
  echo $row["state_id"] . ", ";
  echo $row["zip"] . "\n";
  echo "</td>\n";

  # column 2
  echo "<td valign=\"top\">\n";
  echo "<b>Attention:</b> " . $row["contact_name"];
    # only echo the title if it exists
  if ( !( $row["contact_title"] == '' ) ) {
    echo ", " > $row["contact_title"];
  }
  echo "<br>";
  # only echo the email address if it exists
  if ( !( $row["contact_email"] == '' ) ) {
    echo "<b>Email:</b> <a href=\"mailto:" . $row["contact_email"] . "\">" . $row["contact_email"] . "</a><br>";
  }
  echo "<b>Phone:</b> (" . $row["phone_area"] . ") " . $row["phone_exchange"] . "-" . $row["phone_digits"];
  # only echo the phone extension if it exists
  if ( !( $row["phone_extension"] == '' ) ) {
  echo ", ext. " . $row["phone_extension"];
  }
  echo "<br>\n";
  echo "<b>Fax:</b> (" . $row["fax_area"] . ") " . $row["fax_exchange"] . "-" . $row["fax_digits"];
  # only echo the fax extension if it exists
  if ( !( $row["fax_extension"] == '' ) ) {
    echo ", ext. " . $row["fax_extension"];
  }
  echo "\n";
  echo "</td>\n</tr>\n</table>\n";

}

?>
