<?php
include('connect.php'); //Connect to the database
if(isset($_GET["rid_combo"]))
{
$rid = $_GET["rid_combo"];
$regionquery ="SELECT * FROM tbl_regions WHERE RID = $rid";
$regionresult = mysql_query($regionquery);
$regionrows = mysql_numrows($regionresult);
$rname = mysql_result($regionresult,0,1);
echo "<b><center>Region: $rname</center></b><br><br>"; //Display Region name
$query ="SELECT * FROM tbl_addresses WHERE RID = $rid";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close(); // Close connection to the db as this stops problems with too many connections.
// Create Name Anchors for each of the branch names within the region
echo "<center>";
$i=0;
while ($i < $num) {
$bname=mysql_result($result,$i,"a_name");
echo "<a href='#$bname'>$bname</a> // ";
$i++;
}
echo "</center><hr><br><br>";
//Display all the region info with an anchor for each name.
$i=0;
while ($i < $num) {
$bname=mysql_result($result,$i,"a_name");
$baddress=mysql_result($result,$i,"address");
$bpost_code=mysql_result($result,$i,"post_code");
$bfront_line=mysql_result($result,$i,"front_line");
$bback_line=mysql_result($result,$i,"back_line");
$bmobile=mysql_result($result,$i,"mobile");
$bfax=mysql_result($result,$i,"fax");
$bsite_id=mysql_result($result,$i,"site_id");
$bemail=mysql_result($result,$i,"email");
echo "<b><a name='$bname'>Site: $bname </a></b><br>Address: $baddress , $bpost_code<br>Front Line: $bfront_line<br>Back Line: $bback_line<br>Mobile: $bmobile<br>Fax: $bfax<br>Email: $bemail<br>Site ID: $bsite_id<br><hr><br>";
$i++;
}
}
else
{
//Beginning of combo box to select region name -->
?> <form action="allregions.php?regionid=RID" method="get" target="_self">
<select name="rid_combo" size="1" id="RID">
<?php
$query = "SELECT RID, region FROM tbl_regions";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$RID = $row["RID"];
$region = $row["region"];
?>
<option value="<?php echo $RID; ?>" selected><?php echo htmlentities($region, ENT_QUOTES); ?></option>
<?php
} //End while
?>
</select>
<input type="submit" value="Update" />
</form>
<!-- End of combo box to select region name -->
<?php
}
?>