This topic is locked

use min() in PHP in default values to add page

3/2/2008 6:27:24 PM
PHPRunner General questions
D
deanmeistr author

Trying to build an ADD records page using some calculated fields, but striking out...
I have a "LOGID" unique value field for records, I need to pull the lowest value record and decrease the number by one as the number to insert in the field when I add the record ...Going to the visual editor, I choose Lookup wizard, List of values and try to enter php code into the box of the Default value box...., I assume it should be min(LOGID), but I can't figure how to get it into my Default value box, i tried : [codebox]min(@$avalues["LOGID"])-1[/codebox]
but I get a PHP error on the page as follows: Undefined variable: avalues.
Any suggestions welcome, as to the correct way to pull up that value and decrease it by one.
Dean Meyers

J
Jane 3/3/2008

Dean,
use Add page: Before process event for this purpose.

Here is a sample:

global $conn,$strTableName;

$str = "select min(LOGID) from ".$strTableName;

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);
$_SESSION["LOGID"] = $data[0]-1;


Then use $_SESSION["LOGID"] variables as default value on the "Edit as" settings dialog on the Visual Editor tab.