This topic is locked

Check That A Filed Is Incremented Only By 1

2/26/2013 7:36:19 AM
PHPRunner General questions
A
aptivus author

Hi everyone.

I'm trying to check that a protocol number (a filed of a table) is always incremented by 1.

I made this function in Before Record Added event:

global $conn;
$prev_q = "SELECT MAX(numero_protocollo) as prevProt FROM oabat_protocolli_entrata";

$prev_x = db_query($prev_q,$conn);

$data=db_fetch_array($prev_x);
$diff = ($values['numero_protocollo']-$data['prevProt']);
if($diff==1)

return true;

else

return false;


but the system enter the record even if the difference is more than 1.

What am i missing?

Any suggestion?

Thanks

Sergey Kornilov admin 2/26/2013

Your code looks good to me. If you need more help with it post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.
Another thing - why do you need to make user enter numero_protocollo field manually while only allowing the next available number. You can simply remove 'numero_protocollo' field from the Add page and calculate it on the server side.

global $conn;
$prev_q = "SELECT MAX(numero_protocollo)+1 as prevProt FROM oabat_protocolli_entrata";

$prev_x = db_query($prev_q,$conn);

$data=db_fetch_array($prev_x);
$values['numero_protocollo']=$data['prevProt'];
return true;