在插入PHP MYSQL之前获取Auto_Increment Number [英] GET Auto_Increment Number BEFORE Insertion PHP MYSQL

查看:62
本文介绍了在插入PHP MYSQL之前获取Auto_Increment Number的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个订单管理系统。他们是旧系统,我正在替换他们打开新订单时给他们NEXT订单号。


(即QuickBooks以这种方式行事)


我如何使用PHP MySQL做同样的事情。我正在考虑这个SQL查询


SELECT num FROM table ORDER BY num DESC LIMIT 1;


应该给我最后一个号码,我可以添加一个。


但是我不想查询数据库,因为这将包含数千条记录,而且我担心性能损失。


有没有其他方法可以达到这个目的?以前有人遇到过这个问题吗?


我希望用户输入任何订单号,但会自动建议下一个订单号。这样他们就可以选择一个计划。如果有人在O1000中输入,下一个销售人员在输入新订单时应该看到O1001。


感谢您的帮助,


DM

解决方案

< blockquote>在我看来,以下查询不应占用大量数据库资源:

展开 | 选择 | Wrap | 行号



在我看来,以下查询不应占用大量数据库资源:

展开 | 选择 | Wrap | 行号



他们需要知道订单号,而不是之后。



我不明白你为什么要用户输入订单号。

为什么他们需要输入它才能输入由一个SQL查询计算?


也许我只有一个计数器表。


[专柜]

> ID INT

> TableName VARCHAR()

>编号INT


6个表(订单表是其中之一),我会每次添加一个新订单吗?


这样SQL将查询4记录长表而不是4000记录表。


然而,这是另一种SQL解决方案。猜猜它必须去某个地方,DB就像任何地方一样好。



我刚刚从桌面上的100%以上的记录中测试了一个查询。它需要0.0280秒。


I''m builing an order management system. They''re old system that i''m replacing gives them the NEXT order number when they open a new order.

(ie QuickBooks acts this way)

How can i do the same thing with PHP MySQL. I''m thinking about this SQL query

SELECT num FROM table ORDER BY num DESC LIMIT 1;

that should give me the last number and i can just add one to it.

BUT i do not want to query the DB as this will contains thousands of records and i''m worried about a performance hit.

Is there any other way to achieve this? has anyone encountered this issue before?

I want the user to enter any order number, but automatically suggest the next available one. This way they can "choose" a scheme. If somebody types in O1000, the next sales person should see O1001 when entering a new order.

thanks for your help guys,


DM

解决方案

In my opinion following query should not takes a lot of database resources:

Expand|Select|Wrap|Line Numbers


In my opinion following query should not takes a lot of database resources:

Expand|Select|Wrap|Line Numbers


Their need is to know the order number upon entry, not after.

I don''t understand why you want users to enter order numbers.
Why do they need to enter it while it can be calculated by the one sql query?

Maybe i''ll just have a counter table.

[ Counter ]
> ID INT
> TableName VARCHAR()
> Number INT

6 tables (order table being one of them), i''ll add one each time for a new order is requested?

This way the SQL will query a 4 record long table instead of a 4000 record table.

Yet this is another SQL solution. Guess it has to go somewhere, DB is as good of a place as any.

I''ve just tested a query from my pervious post on the table with 100 000+ records. It takes 0.0280 seconds.


这篇关于在插入PHP MYSQL之前获取Auto_Increment Number的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆