increment number

DANINAP

Member
Hello everyone. I have a movement table where there is a center field and a number field that I have to increase automatically based on the center field ex. center A num 1,2,3,4 center B num 1,2,3,4 increase the with the max number + 1 of each center. how can I do ?
 
sorry ...
when to add the form element what kind of field should I choose? I can't find the calculation item
 
thanks.
i managed to install the plugin missing and I entered this code:
//
$ db = FabrikWorker :: getDbo ();
$ query = $ db-> getQuery (true);
$ query-> clear ()
-> select ('max (numero_di_pratica) +1')
-> from ($ db-> quoteName ('movimenti'));
$ db-> setQuery ($ query);
$ count = $ db-> loadResult ();
return $ count;
//
unfortunately it does not give me any value back what am I writing wrong?
 
How about this:
Code:
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$query
    ->select('max(numero_di_pratica) +1')
    ->from($db->quoteName('movimenti'));
$db->setQuery($query);
$count = $db->loadResult();
return $count;
Please note: I removed 26 spaces (and a little bit else). If the DB table name "movimenti" is correct (no prefix?), it might work.
 
What are you getting, what are you seeing in the list?
Any errors? Also checked logs?
The column "numero_di_pratica" exists in the table named "movimenti"?
What exactly are you inserting in what I believe is the "Calculation" field in the calc element, and what are the other settings in that tab of the calc element? (Screenshot?)
What if you remove your code and, instead, simply and only insert
Code:
return '123';
(You should have a column with values 123 in every row.)
 
in the list the field is empty could it be because there are no records and returning null doesn't increment it?

I have no errors on the screen
 
Of course, with no records = rows in the table at all, there's nothing to return or see, indeed, and it's pointless to continue this until you have some content.
 
here is the screen of the list
Ok, and I dare guessing the list column "Numero Pratica" is the DB table named "numero_di_pratica", but in the context of this thread that's all I can see from here, and factually that's also only a wild guess.
yes but inserting the first record should give the number 1
With correct code in a calc element that's set to display in the list and at least one row existing: yes.
But I asked (and haven't got helpful answers):
What are you getting, what are you seeing in the list?
Any errors? Also checked logs?
The column "numero_di_pratica" exists in the table named "movimenti"?
What exactly are you inserting in what I believe is the "Calculation" field in the calc element, and what are the other settings in that tab of the calc element? (Screenshot?)
What if you remove your code and, instead, simply and only insert
Code:
return '123';
(You should have a column with values 123 in every row.)
So... sorry, but without sufficient information no one can help you from the distance.
 
sorry but if I wanted to take the value of a field before saving the record to pass it to the query what is the syntax ..
I should insert a "where" with the value of a field inserted in input but still to be saved
sorry if I stress you
 
I'm sorry again the calculation must be made only in insertion, I saw that it always increases even if I change other fields ..
 
sorry but if I wanted to take the value of a field before saving the record to pass it to the query what is the syntax ..
I should insert a "where" with the value of a field inserted in input but still to be saved
sorry if I stress you
This would give you generally at least two options, depending on what exactly you need: either use the Ajax features of the calc element, or use a PHP form plugin.
I'm sorry again the calculation must be made only in insertion, I saw that it always increases even if I change other fields ..
This latest note seems to call for your use of the PHP form plugin.
 
I saw how to add the php plugin and where to insert.
Come on if you assign the value to the field with the code you recommended?

$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$query
->select('coalasce(max(numero_pratica),0 +1')
->from($db->quoteName('movimenti'));
$db->setQuery($query);
$count = $db->loadResult();
return $count;

I have to assign the maximum value to number_pratica
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top