Hi,
I was looking for the answer that I could have the SC to set up the limit number for adding the record(s). For example: The user could fill the data on only 2 or 3 forms (or different profiles like payee, second party, etc.) , but not be able to fill more than 3 forms. How can I do that way? Or can you please point me where to find for me to learn how to do.
Thanks.
crwatson07
First you need to mark every record so that you recognize it as being a form belonging to that user. I.e. by adding the user name or email address to the record. To prevent more than x records you can use a simple select count * from table where userid=your user. If the count is reached then you return to the menu, lock the menu item or something like that. If you have records in more than one table you can do this for each table. To increase speed on large tables you could set an index on the userid.
Hello Albert,
I know about MySQL very little… Can you give me the sample code, please?
Many Thanks! Plus Thanks for your quick reply.
crwatson07
Just add a field ‘owner’ to the tables you want to test. You can do that with the database builder in scriptcase.
In the logonpage set a global variable containing the user [glob_owner]={userid};
In the forms where you have the extra field go to edit fields and set default value on insert for the global [glob_owner]. Set force value checkbox to true
In the onbeforeinsert test for the max occurances using
select count(*) from “your table” where owner=[glob_owner];
if count > 3 then error exit (see code snippet on the right)
in the onafterinsert do the same test. If count >= 3 then jump to the menu and remove the menuitem (see macro in the manual, it has good samples)
I think that should do it.
Got it. Let me make myself to understand… Using the ONE table wiith many fields with different profiles, it will run faster than using more than one table, correct?
I am learning.
That depends. I.e. the number of records, indexes. In general it is very important to think about your database model before you start to create your application. SC is very database driven so that DB changes will cause a lot of work. I prefer to ignore the performance issues as I think that they are nowadays less important and concentrate on normalisation of the database model. But of course if you have very large resultsets you have to make consessions now and then. Bad structured database will also in general lead to a bad working application.