This topic is locked
[SOLVED]

 need help on auto value field

4/13/2011 2:21:38 PM
PHPRunner General questions
hapony author

Hi there,

im using phprunner,

i want to made automatic value on a field base on value from last record,

example :

i hade field : id ( int, autoincrement), field name ( varchar ) and id number field (uniqe) , and i want id_number field is generated automatically when i'm adding record, the format of the id number like ???-01-2011 ( ??? is number generated automatic , 01 is value from month format within month of record addedd , 2011 isvalue from year format within year of record addedd.
so it's gonna like this , first record for example 001-01-2011 , when i clik add record for new record, the text field of id_number will automatically insert 002-01-2011 , and till the current month / year chance to next moth or year , the id_number will reset and begin from 001 again with defrent month, for example 001-02-2011,
can any one help me,

sorry for bad english, hope you guys's understand and can help me..

Thanks and regards
Boni

J
Jane 4/14/2011

Hi,
use After record added event to generated this value and save it in the database.

Here is just a sample:

$rstmp = CustomQuery("select max(id) as max_id from TableName where SUBSTRING(id_number,5,2)=MONTH(now());");

$datatmp = db_fetch_array($rstmp);

if (!$datatmp["max_ID"])

$next = "001";

else

$next = $datatmp["max_ID"]+1;
if ($next<10)

$next="00".$next;

if ($next>9 && $next<100)

$next="0".$next;
$next.=date("m")."-'.date("Y");
hapony author 4/14/2011

Hi Jena,

Thanks for the code.. and still on test

regard's

A
ashumak 4/22/2011



Hi Jena,

Thanks for the code.. and still on test

regard's


with a table of info, ID as the autoincrement field, and member_number as the field I want to update, I get this error:

Parse error: syntax error, unexpected T_STRING in /mnt/r0522/d27/s16/b02c3c6d/www/torontoaikido.com/aikimembers/include/info_events.php on line 34
Using code:

$rstmp = CustomQuery("select max(id) as max_id from info where SUBSTRING(member_number,5,2)=MONTH(now());");

$datatmp = db_fetch_array($rstmp);

if (!$datatmp["max_ID"])

$next = "001";

else

$next = $datatmp["max_ID"]+1;
if ($next<10)

$next="00".$next;

if ($next>9 && $next<100)

$next="0".$next;
$next.=date("m")."-'.date("Y");

did I miss something?
Alan