prepare($myQuery); /*Bind the parameter*/ $stmt->bind_param('i', $pk_id); /*Execute the query*/ $stmt->execute(); /*Store the results*/ $stmt->store_result(); /*If results, then bind to variable*/ if($stmt->num_rows === 1){ $stmt->bind_result($retVal); $stmt->fetch(); $stmt->close(); }#end if num_rows else{ exit('no records available'); }#end else num_rows return $retVal; }#end getOneValIntKey /*This function will query the db for whichever 2 values ($key, $val) are needed. Then it will return those values in an array for easy use. The params - $dbLink is the connection link to the db, $myQuery is the query sent by the calling code, $key is the value from the db table that will act as the key in the array, $val is usually the value seen in the dropdown, $pk_id is an integer value that will be used as the criteria in the query WHERE clause. */ function getValuesListIntKey($dbLink, $myQuery, $key, $val, $pk_id = null){ /* Prepare the statement */ $stmt = $dbLink->prepare($myQuery); /* Bind the parameter */ $stmt->bind_param('i', $pk_id); /* Run the query */ $stmt->execute(); /* Fetch the results */ $resultList = $stmt->get_result(); /* Declare array for returning result list to calling page */ $allRows= array(); /* Put the building id and the building name into an array to return */ while($row = $resultList->fetch_assoc()){ $allRows[$row["$key"]] = $row["$val"]; }#end while $stmt->close(); return $allRows; }#end getValuesListIntKey /*This function will query the db for whichever 2 values ($key, $val) are needed. Then it will return those values in an array for easy use. The params - $dbLink is the connection link to the db, $myQuery is the query sent by the calling code, $key is the value from the db table that will act as the key in the array, $val is usually the value seen in the dropdown, $pk_id is a string value that will be the criteria in the query WHERE clause. */ function getValuesListCharKey($dbLink, $myQuery, $key, $val, $pk_id = null){ /* Prepare the statement */ $stmt = $dbLink->prepare($myQuery); /* Bind the parameter */ $stmt->bind_param('s', $pk_id); /* Run the query */ $stmt->execute(); /* Fetch the results */ $resultList = $stmt->get_result(); /* Declare array for returning result list to calling page */ $allRows= array(); /* Put the key id and the value into an array to return */ while($row = $resultList->fetch_assoc()){ $allRows[$row["$key"]] = $row["$val"]; }#end while $stmt->close(); return $allRows; }#end getValuesListCharKey function getAllValuesListNoKey($dbLink, $myQuery, $key, $val){ /* Prepare the statement */ $stmt = $dbLink->prepare($myQuery); /* Bind the parameter */ #$stmt->bind_param('i', $pk_id); /* Run the query */ $stmt->execute(); /* Fetch the results */ $resultList = $stmt->get_result(); /* Declare array for returning result list to calling page */ $allRows= array(); /* Put the building id and the building name into an array to return */ while($row = $resultList->fetch_assoc()){ $allRows[$row["$key"]] = $row["$val"]; }#end while $stmt->close(); return $allRows; }#end getValuesListIntKey function insertTblwhatif($dbLink, $idList, $snid){ /* This will copy all records in the tblwhatif table that belong to the old_save_name and insert them into the tblwhatif table with identical data except for the save_name_id. The new save_name_id belonging to the new_save_name that was entered by the user will replace the old_save_name_id for the copied records. */ #Create the query $q = "INSERT INTO tblwhatif (`save_name_id`, `fpm_id`, `ID#`, `building_id`, `NewSerialNum`, `SerialNum`, `Features`, `speed`, `Annual Volume`, `BidMeter`, `Intro`, `Life`, `MoveTo`, `MoveFrom`, `1stYearEquipment`, `PropVol`, `2ndYear`, `NewVendorID`, `VendorID`, `VendorName`, `AdjCostCopy`, `GroupTag`, `PropCost`, `ForcedUpgrades`, `S&&S`, `Install`, `lease`, `Color_Vol`, `Color_CPC`, `NewColorCPC`, `ProjColorVol`, `IP_Address`, `Special_Notes`, `prop_life`, `prop_intro`, `mac_address`, `present_type_id`, `present_model_id`, `proposed_model_id`, `present_floorplan_id`, `present_room_number`, `commencement_blk_meter`, `commencement_color_meter`, `dept_id`, `vendor_black_cpc_proposed`, `vendor_color_cpc_proposed`, `Modified`, `Created`, `Created By`, `Modified By`) SELECT " . $snid . ", `fpm_id`, `ID#`, `building_id`, `NewSerialNum`, `SerialNum`, `Features`, `speed`, `Annual Volume`, `BidMeter`, `Intro`, `Life`, `MoveTo`, `MoveFrom`, `1stYearEquipment`, `PropVol`, `2ndYear`, `NewVendorID`, `VendorID`, `VendorName`, `AdjCostCopy`, `GroupTag`, `PropCost`, `ForcedUpgrades`, `S&&S`, `Install`, `lease`, `Color_Vol`, `Color_CPC`, `NewColorCPC`, `ProjColorVol`, `IP_Address`, `Special_Notes`, `prop_life`, `prop_intro`, `mac_address`, `present_type_id`, `present_model_id`, `proposed_model_id`, `present_floorplan_id`, `present_room_number`, `commencement_blk_meter`, `commencement_color_meter`, `dept_id`, `vendor_black_cpc_proposed`, `vendor_color_cpc_proposed`, `Modified`, `Created`, `Created By`, `Modified By` FROM tblwhatif WHERE id = ?"; /* Prepare the statement, and if successful continue. */ if($stmt = $dbLink->prepare($q)){ $rowCount = 0; foreach($idList as $i => $value){ $oldSnid = $idList[$i]; $rowCount += 1; #Bind parameters $stmt->bind_param('i', $oldSnid); #Run query $stmt->execute(); }#end foreach #Close statement $stmt->close(); return $rowCount; }#end if $stmt }#end insertTblwhatif function insertTblwhatifNull($dbLink, $idList, $snid){ /* This will copy all records in the tblwhatif table that belong to the old_save_name and insert them into the tblwhatif table with identical data except for the save_name_id and some vol fields that will be made null. The new save_name_id belonging to the new_save_name that was entered by the user will replace the old_save_name_id for the copied records. The dbLink is also passed as an arg so it will only need to be created once.*/ #Create the query $q = "INSERT INTO tblwhatif (`save_name_id`, `fpm_id`, `ID#`, `building_id`, `NewSerialNum`, `SerialNum`, `Features`, `speed`, `Annual Volume`, `BidMeter`, `Intro`, `Life`, `MoveTo`, `MoveFrom`, `1stYearEquipment`, `PropVol`, `2ndYear`, `NewVendorID`, `VendorID`, `VendorName`, `AdjCostCopy`, `GroupTag`, `PropCost`, `ForcedUpgrades`, `S&&S`, `Install`, `lease`, `Color_Vol`, `Color_CPC`, `NewColorCPC`, `ProjColorVol`, `IP_Address`, `Special_Notes`, `prop_life`, `prop_intro`, `mac_address`, `present_type_id`, `present_model_id`, `proposed_model_id`, `present_floorplan_id`, `present_room_number`, `commencement_blk_meter`, `commencement_color_meter`, `dept_id`, `vendor_black_cpc_proposed`, `vendor_color_cpc_proposed`, `Modified`, `Created`, `Created By`, `Modified By`) SELECT " . $snid . ", `fpm_id`, `ID#`, `building_id`, `NewSerialNum`, `NewSerialNum`, `Features`, `speed`, `PropVol`, NULL, `Intro`, `prop_life`, NULL, NULL, `1stYearEquipment`, `PropVol`, NULL, NULL, `NewVendorID`, NULL, `PropCost`, NULL, NULL, NULL, `S&&S`, NULL, `lease`, `ProjColorVol`, `NewColorCPC`, NULL, `ProjColorVol`, `IP_Address`, `Special_Notes`, `prop_life`, `prop_intro`, `mac_address`, `present_type_id`, `proposed_model_id`, `proposed_model_id`, `present_floorplan_id`, `present_room_number`, `commencement_blk_meter`, `commencement_color_meter`, `dept_id`, `vendor_black_cpc_proposed`, `vendor_color_cpc_proposed`, `Modified`, `Created`, `Created By`, `Modified By` FROM tblwhatif WHERE id = ?"; /* Prepare the statement, and if successful continue. */ if($stmt = $dbLink->prepare($q)){ $rowCount = 0; foreach($idList as $i => $value){ $oldSnid = $idList[$i]; $rowCount += 1; #Bind parameters $stmt->bind_param('i', $oldSnid); #Run query $stmt->execute(); }#end foreach #Close statement $stmt->close(); return $rowCount; }#end if $stmt }#end insertTblwhatifNull function getTblwhatifRecords($dbLink, $snid, $oldSnid, $makeNull){ /* This will get the list of ID values from tblwhatif that belong to the old save_name_id, which was passed as an arg. The new save name id from the newly created fyer_group was passed as an argument to be forwarded to the insertTblwhatif function. The dbLink is also passed as an arg so it will only need to be created once.*/ #create the query $q = "SELECT `ID` id FROM `tblwhatif` WHERE save_name_id = ?"; /* Prepare the statement, and if successful continue. */ if($stmt = $dbLink->prepare($q)){ #An array to hold the tblwhatif.id values for the fyer_group, the $oldSnid $idList = array(); #bind parameters $stmt->bind_param('i', $oldSnid); #run the query $stmt->execute(); #bind the results variables $stmt->bind_result($id); #fetch values while($stmt->fetch()){ #Add the current id from tblwhatif to the array $idList[] = $id; }#end while /* Pass the db connection for prepared statements, $idList array of tblwhatif.id values, and the new save name id to insertTblwhatif, which will insert the new data. */ $successMsgA = "There were "; $successMsgB = ""; if($makeNull){ $successMsgB = insertTblwhatifNull($dbLink, $idList, $snid); } else{ $successMsgB = insertTblwhatif($dbLink, $idList, $snid); } $successMsgC = " inserted."; $successMsg = $successMsgA . $successMsgB . $successMsgC; return $successMsg; #Close statement $stmt->close(); }#end if }#end getTblwhatifRecords ?>