This topic is locked

Auto number on Inline Add

1/20/2011 8:12:16 AM
PHPRunner General questions
J
jianwong author

I have a Detail List page with a field intended to display number in sequence.

When I Inline Add, a number "1" will display in this field.

Inline Add another record, a number "2" will display in that field.

It adds on as new record added.

Can any member advise how to do it?

Some sample code or link site where I can get tutorial will be appreciate.

J
Jane 1/20/2011

Hi,
use Add page: Before process event on the Eventstab to calculate this value and save it in the session variable.

Here is a sample:

global $strTableName;

$rstmp = CustomQuery("select max(IDField) as `m` from TableName where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$datatmp = db_fetch_array($rstmp);

$_SESSION["Nextnumber"] = $datatmp["m"]+1;



Then use $_SESSION["Nextnumber"] as default value on the "Edit as" settings dialog on theVisual Editor tab.

J
jianwong author 1/20/2011



Hi,
use Add page: Before process event on the Eventstab to calculate this value and save it in the session variable.

Here is a sample:

global $strTableName;

$rstmp = CustomQuery("select max(IDField) as `m` from TableName where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$datatmp = db_fetch_array($rstmp);

$_SESSION["Nextnumber"] = $datatmp["m"]+1;



Then use $_SESSION["Nextnumber"] as default value on the "Edit as" settings dialog on theVisual Editor tab.


Hi Jane
I follow the sample event code, unfortunately it produced error as in below.

Please advise where wrong.

===============================

Error description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

URL: jianwong.com/csauto/JobDetail_add.php?

Error file: /home/jianwong/public_html/csauto/include/dbconnection.php

Error line: 36

SQL query: select max(IDField) as m from TableName where DetailKey=

V
Vienna 1/20/2011



Hi Jane
I follow the sample event code, unfortunately it produced error as in below.

Please advise where wrong.

===============================

Error description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

URL: jianwong.com/csauto/JobDetail_add.php?

Error file: /home/jianwong/public_html/csauto/include/dbconnection.php

Error line: 36

SQL query: select max(IDField) as m from TableName where DetailKey=

===============================


From what I can tell where it says "TableName" inside the Custom Query you went ahead and used it exactly like that without replacing "TableName" with the exact name of YOUR SPECIFIC project table where you want that detailkey to match up.
It is inside that query string "select max(IDField) as m from theTableNameyouwant where DetailKey="
from my own project I would have written that as "..from doctor_address where DetailKey....

J
jianwong author 1/20/2011



From what I can tell where it says "TableName" inside the Custom Query you went ahead and used it exactly like that without replacing "TableName" with the exact name of YOUR SPECIFIC project table where you want that detailkey to match up.
It is inside that query string "select max(IDField) as m from theTableNameyouwant where DetailKey="
from my own project I would have written that as "..from doctor_address where DetailKey....


Hi Vienna
Thank you for sharing.

My table name is JobDetail, I changed the code as in below, however, it still produced the same error.

Must I change the "(IDField)" also? Please advise.
====================

global $strTableName;

$rstmp = CustomQuery("select max(IDField) as m from JobDetail where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$datatmp = db_fetch_array($rstmp);

$_SESSION["Nextnumber"] = $datatmp["m"]+1;

romaldus 1/20/2011



Hi Vienna
Thank you for sharing.

My table name is JobDetail, I changed the code as in below, however, it still produced the same error.

Must I change the "(IDField)" also? Please advise.
====================

global $strTableName;

$rstmp = CustomQuery("select max(IDField) as m from JobDetail where DetailKey=".$_SESSION[$strTableName."_masterkey1"]);

$datatmp = db_fetch_array($rstmp);

$_SESSION["Nextnumber"] = $datatmp["m"]+1;

====================


Note: this script cannot used in AUTONCREMENT field in database. For example, if IDField in JobDetail table is a Primary key and autoincrement by database engine.

J
jianwong author 1/21/2011



Note: this script cannot used in AUTONCREMENT field in database. For example, if IDField in JobDetail table is a Primary key and autoincrement by database engine.


Hi,

I go into database to disable AutoIncrement on the Primary key, which is named JobDetail.

But it won't help.

I replaced the "(IDField)" to "(No)", the field where the running number intended to show.

Yet, to no avail.

Any suggestion, please advise. Thanks.