I have defined a PHP function that works absolutely fine but I am facing a problem. I am trying to call GenerateIDNumber function multiple times on same page with different values but its returning the same value of first time defined variables, is there any way to close/end the function and recall it with new values.
Here is my code
<?php
/* GenerateID Number */
function GenerateIDNumber($tablenames, $columnnames)
{
global $conn;
global $highest_id;
$sql = "SELECT MAX(" . $columnnames . ") as max FROM " . $tablenames;
$rs = mysqli_query($conn, $sql);
$result = mysqli_fetch_row($rs);
if ($result[0] >= 1) {
$highest_id = $result[0] + 1;
} else {
$highest_id = 1;
}
}
/* GenerateID Number */
$highest_id = null;
$mytable_name = "tblleasesalespayment";
$mycolumn_name = "PaymentID";
GenerateIDNumber($mytable_name, $mycolumn_name);
$printNumber = $highest_id;
$SaleIDGenerator = "CRV-";
$SetNumberCust = $SaleIDGenerator . $_SESSION['ACTBRANCHID'] . date('y') . sprintf("%08s", $printNumber);
$Code1 = $SetNumberCust;
$highest_id = null;
$mytable_name = "tblrepossess_vehicles";
$mycolumn_name = "rp_id";
new GenerateIDNumber($mytable_name, $mycolumn_name);
$printNumber = $highest_id;
$SetNumberCust = "REP-" . $_SESSION['ACTBRANCHID'] . date('y') . sprintf("%08s", $printNumber);
$Code2 = $SetNumberCust;
?>
global"feature"...returnstatement.$highest_idis used to combine with the returning valueglobalkeyword! It is evil! It causes huge issues. Return the value you compute from the function, then things work. Read the php documentation about how functions are used in php.