This topic is locked

Displaying ID

5/2/2014 9:12:21 AM
PHPRunner General questions
B
bijayapun author

I have an application form and i want to display the application ID to user while they fill the form. So it needs to check the last application ID and add 1 on that. Since it is a single user database, there shouldn't be a duplication issue. I would appreciate it if anybody here knew the trick.
Thanks

J
jmclain 5/2/2014



I have an application form and i want to display the application ID to user while they fill the form. So it needs to check the last application ID and add 1 on that. Since it is a single user database, there shouldn't be a duplication issue. I would appreciate it if anybody here knew the trick.
Thanks


Probably a bunch of ways to approach this -- but you could do the following.

Within Visual Editor, insert PHP code snippet - somewhere on your page. Now insert something like this for your code. Please note - this is an example and change as needed.

$sql="select top 1 APP_ID from dbo.YOUR_APP_TABLE order by APP_ID desc"; //Query to get the last ID number in the table

$data=db_fetch_array(CustomQuery($sql));

echo "APPLICATION ID: " . ++$data["APP_ID"]; //Display APP ID from query and add 1
F
F5447 5/3/2014



I have an application form and i want to display the application ID to user while they fill the form. So it needs to check the last application ID and add 1 on that. Since it is a single user database, there shouldn't be a duplication issue. I would appreciate it if anybody here knew the trick.
Thanks



This is not practical ... for example:

Let say A, click your page to fill up a form, and the ID is [your database last ID]+1, but he remain in the filling up form page

Then say B, click your page to fill up a from, then the ID also [your database last ID]+1, which is same with A ...
[size="4"]Oh sorry, mislook at your "a single user database" phrase.[/size]

B
bijayapun author 5/3/2014



Probably a bunch of ways to approach this -- but you could do the following.

Within Visual Editor, insert PHP code snippet - somewhere on your page. Now insert something like this for your code. Please note - this is an example and change as needed.

$sql="select top 1 APP_ID from dbo.YOUR_APP_TABLE order by APP_ID desc"; //Query to get the last ID number in the table

$data=db_fetch_array(CustomQuery($sql));

echo "APPLICATION ID: " . ++$data["APP_ID"]; //Display APP ID from query and add 1



Thanks for the information. I managed to display the APP_ID through php snippet. However, i want to give that value to field so that it will be submitted too. Lookup table gave me the next id using max(APP_ID)+1 however it comes with drop down box. I wanted to show read only value of APP_ID.

J
jmclain 5/3/2014



Thanks for the information. I managed to display the APP_ID through php snippet. However, i want to give that value to field so that it will be submitted too. Lookup table gave me the next id using max(APP_ID)+1 however it comes with drop down box. I wanted to show read only value of APP_ID.


OK. I would use the existing snippet since it is working for you. Just modify the snippet to set lookup value to a SESSION . . .

$sql="select top 1 APP_ID from dbo.YOUR_APP_TABLE order by APP_ID desc"; //Query to get the last ID number in the table

$data=db_fetch_array(CustomQuery($sql));

$_SESSION['APP_ID']= ++$data["APP_ID"]; //Save result to a session

echo "APPLICATION ID: " . $_SESSION['APP_ID']; //Display APP ID from query and add 1


Now change the field in Visual Editor to read-only and insert the $_SESSION['APP_ID'] in the default and auto-update fields.
Please Note: I know this is a single user database - but typically this is not the best way to handle something like this. Should be taken care of by the database by using auto-increment. But is this works for you, then so be it <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=74701&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />