Default Value of Select Field Equals Highest Value

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
neodaemon
User
Posts: 61

Default Value of Select Field Equals Highest Value

Post by neodaemon »

I'm using 2022.12.2
I'm trying to set the default value of a select field to its highest possible value. The select field stores the ID of its lookup table.

This reference is from an old version and does not work:
viewtopic.php?p=103949&hilit=default+va ... id#p103949

...I think it has partially to do with the current PHP version having stricter parameter handling.

I have the select field results sorted DESC; which at least helps when selecting a value manually. But I would like the default value to appear in the field, and set to the highest possible ID which is stored in that field, and supplied by its lookup table.

Thanks in advance for any help or pointers in the right direction.


mobhar
User
Posts: 11660

Post by mobhar »

You may simply use Row_Rendered server event to do this.

Just use ExecuteScalar global function to get the single highest value in that Select field, after that, just assign that value to the CurrentValue property of the field. Please try it by yourself first, and you may post your code for more discussion.


neodaemon
User
Posts: 61

Post by neodaemon »

This failed, probably because I am a poor coder. Following is my code:
$myField = ExecuteScalar("SELECT max(eventid) FROM events");
$this->eventid->currectvalue == $myField;

The error I get is:
Warning: Undefined property: PHPMaker2022\gman2022\DbField::$currectvalue


arbei
User
Posts: 9292

Post by arbei »

  1. Property name is case-sensitive (Method name is case-insensitive though).
  2. Use assignment operator "=", not "==" which is comparison operator.

neodaemon
User
Posts: 61

Post by neodaemon »

Thanks for the tip. After following those two pointers it worked.
Thanks again,


Post Reply