I have the following function in place to allow people to change the status of their payment gateway from "inactive" to "active". Currently this function allows users to have as many gateways of any type to be active or inactive at any given point. I decided that I only want them to allow one gateway of the type "Direct" to be "active" at one time. Thus in order to make a different "direct" gateway to be "active they would have to inactivate the current gateway. The gateway type is being stored in a table called "gateway". If anyone could give me some pointers on how to make this happen i would highly appreciate it.

function store_gateway_status ($STORE, $GATEWAY){
GLOBAL $DB;
$ERROR = "";
$SQuery = "SELECT SG1.Status AS StoreGatewayStatus "
. " FROM ".$DB['Table']['StoreGateway']." AS SG1 "
. " WHERE SG1.StoreID='".$STORE['ID']."' "
. " AND SG1.GatewayID='".$GATEWAY['ID']."' ";
$SResult = mysql_query($SQuery, $DB['Link']);
$SRow = mysql_fetch_object($SResult);
$StoreGatewayStatus = $SRow->StoreGatewayStatus;
if ($StoreGatewayStatus == 'Inactive'){
$StoreGatewayStatus = 'Active';
}
else {
$StoreGatewayStatus = 'Inactive';
}
$UQuery = "UPDATE ".$DB['Table']['StoreGateway']." AS SG1 "
. " SET SG1.Status='".$StoreGatewayStatus."' "
. " WHERE SG1.StoreID='".$STORE['ID']."' "
. " AND SG1.GatewayID='".$GATEWAY['ID']."' ";
$UResult = mysql_query($UQuery, $DB['Link']);
if (strlen(mysql_error($DB['Link'])) > 0){
$ERROR = $ERROR."<BR>".mysql_error($DB['Link']);
}
return ($ERROR);