ManishaS ManishaS - 6 months ago 21
PHP Question

how to get next batch number corresponding to product code with php mysql

Please help me to find next batch number corresponding to product code with using PHP and MySQL. My table is like below given image:

Table Screenshot

If I want to enter new batch of product RM-SO-070G then the PHP form must get new batch number accordingly.

Answer

Your SQL should look something like this ...

SELECT `some_tbl`.`batch_no` FROM `some_tbl` WHERE `some_tbl`.`product_code` = ? ORDER BY `some_tbl`.`batch_no` DESC LIMIT 1

And then once you get these results you will need to remove the bt from the front of the batch_no

$next_batch_no = intval(substr($result_row['batch_no'], 2))++;