This topic is locked

Limit Series (Bank Cheque Book)

12/6/2011 10:20:51 PM
PHPRunner General questions
A
angelcause author

I am working on a bank cheque tracking system, but am stuck :
I have a table in which holds the cheque book start and end serial (00001-00050)"tbl_chq_book"

Fields of tbl_chq_book are :

id

cheque_book_no

serial_start

serial_end

and another table to add an individual cheque description once its issued "tbl_chq_issued"

Fields of tbl_chq_issued are:

id

cheque_no

description

issued_to

issued_date

I want tbl_chq_issued to automatically see if the cheque book serial exists in tbl_chq_book and then save the record else it should show an error.
Please tell me what code do I have to use, also make sure there is only a start and end serial numbering system.
Thanks for the help in Advance

C
cgphp 12/7/2011

In the "Before record added" event of the tbl_chq_issued table, enter this code:

$rs = CustomQuery("SELECT serial_start, serial_end FROM tbl_chq_book WHERE cheque_book_no = ".$values['cheque_no']." LIMIT 1");

$record = db_fetch_array($rs);
if(is_null($record['serial_start']) OR is_null($record['serial_end']))

{

$message = "Error: the serial_start value or the serial_end value are missing";

return false;

}


If the cheque_book_no field is a VARCHAR use this code:

$rs = CustomQuery("SELECT serial_start, serial_end FROM tbl_chq_book WHERE cheque_book_no = '".$values['cheque_no']."' LIMIT 1"); //the difference between this code and the above one is the single quote for the cheque_book_no value

$record = db_fetch_array($rs);
if(is_null($record['serial_start']) OR is_null($record['serial_end']))

{

$message = "Error: the serial_start value or the serial_end value are missing";

return false;

}