-2

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.

4

3 回答 3

0

创建一个额外的表,它将作为一个序列器 - 该表将只有一个列保存下一个批次值。每次将新产品添加到初始表时,您都会从排序器表中获取批号,并使用您希望添加的下一个产品的下一个批号更新排序器。

于 2013-08-30T15:56:45.030 回答
0

您的 SQL 应该看起来像这样......

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

然后一旦你得到这些结果,你需要bt从前面删除batch_no

$next_batch_no = intval(substr($result_row['batch_no'], 2))++;
于 2013-08-30T16:00:03.273 回答
0

尝试这个:

$product = "RM-SO-070G";
$previous = "bt001";
$query = "SELECT batch_no FROM table WHERE product_code = '".$product."' 
              AND batch_no = (SELECT MIN(batch_no) FROM table 
                  WHERE batch_no > '".$previous."');";
$result = mysql_query($query);
...
于 2013-08-30T16:00:28.083 回答