substring on datafield

Hello,

i have a little problem with substr.

My problem, i got a barcode in a field. Now the last 4 Digits of the Barcode are the Production Quantity of the product.
as i need this value to calculate the rest of the production, my table has also a field where this quantity should be stored.
i think that a substr(barcode,-1,4) should give me the right value, but i could not figure out how to transfer it with Ajax in my quantity field.

Ideas are welcome !
Gerd

Re: substring on datafield

If the barcode is already there, then use mysql’s RIGHT to send the data to the qty field


update table set qty = right(barcode,4);

If you need to send it in code using php:


$qty = substr({barcode_field},-4);
or
{qty_field} = substr({barcode_field},-4);

You mention ajax … are you trying to make a manual ajax call?

Regards,
Scott.

Re: substring on datafield

Hello Scott,

meaning ajax, yes !

i defined a table with a char field and an integer field, putted a value in it “12345678” and try to do the substr. “5678” to the integer field.
I have to use a char field, as it is possible that the user has to give the amount per hand, if the scanner is not working any more

Gerd

Re: substring on datafield

In SC IDE:

Select barcode field
Select AJAX events/New AJAX event
Select barcode field in dropdown in main window
Select onblur event (or onchange)
Select barcode field
-CREATE Event
In the Editor:

$sql = 'UPDATE table SET qty = right({barcode},4)';
sc_exec_sql($sql);

This should update the field when you change/leave the barcode field.

Regards,
Scott.

Re: substring on datafield

Thx Scott,

i will test it when my DB connection is working again !

Regards

Gerd