Get Max field value of MySQL Table by PHP

This function helps to get the max value of the table for the field. You will just require to pass the field which you want the max value and the table name it will return the max value of that field.

 PHP |  copy code |? 
01
02
	function getMaxIDFRMTable($sTabName,$sField)
03
	{
04
		$sQuery = "SELECT MAX(".$sField.") FROM ".$sTabName;
05
		try
06
		{
07
			$conn = dbcon::getConn();
08
			$iMax = $conn->GetOne($sQuery);
09
			return intval($iMax);
10
		}
11
		catch (Exception $e) {
12
			logMessage($e->getMessage(),BR_LOG_ERROR);
13
			return null;
14
		}
15
	}
16

  • Share/Bookmark
No Responses to “Get Max field value of MySQL Table by PHP”

Post a Comment