不使用try catch重写 [英] Rewrite without using try catch
问题描述
数据库中的ID以abc_001,abc_002的形式保存,或者它们可能是abc_asd,abc_a12
我运行一个代码来检查ID的最高数字后缀。<在上述情况下,
,它将返回 3 。
这里是代码。
IDs in the database are saved in the form of abc_001, abc_002 or they may be abc_asd, abc_a12
I run a code to check the highest numerical suffix of the ids.
in the above case, it would return 3.
Here''s the code for that.
推荐答案
不知道,但是如何在数据库中使用ID列(数值自动增量)然后有包含您描述的系统的内部ID列。只是如果你命名的东西并在名称中包含数字,实际上它是一个字符串,所以你总是需要variant_int()或类似的东西来转换它。
No idea, but what about using an ID column in the database (numerical auto-increment) and then have an internal ID column with the system you describe. It''s just if you are naming something and include numbers in the name, really, it is a string, and so you will always need the variant_int() or something like it to convert it.
您可以使用 is_numeric 功能检查字符串是否为数字。
您可以尝试以下方法:
You can use the is_numeric function to check whether a string is a number or not.
You could try something like:
我不得不想,你为什么要用这样复杂的ID是你的表吗?
使用带auto_increment的整数更简单。
I have to wonder tho, why do you use such complex ID''s for you table?
It is faaar simpler to use an integer with auto_increment.
不知道,但是如何在数据库中使用ID列(数值自动增量),然后在系统中有一个内部ID列描述。只是如果你命名的东西并在名称中包含数字,实际上,它是一个字符串,所以你总是需要variant_int()或类似的东西来转换它。
No idea, but what about using an ID column in the database (numerical auto-increment) and then have an internal ID column with the system you describe. It''s just if you are naming something and include numbers in the name, really, it is a string, and so you will always need the variant_int() or something like it to convert it.
实际上它看起来有点复杂。 Ids,不仅可以是 abc_001 的形式,还可以是 xyz_001 或 abc_xxx 或简单地 abcdef 。而且ID不是由用户制作的,而是由管理员制作的。因此,如果他输入前缀 abc 并想要生成10个ID,Ajax将检查数据库中所请求后缀的最高前缀(我正在做给定的代码片段并弹出一个div,其中一个表单显示那些10个ID的注册。所以自动增量无法解决。希望你了解我的情况。
谢谢:)
Harpeet
Actually its a little bit complex than it seems. Ids, can not only be in the form of abc_001, but also xyz_001 or abc_xxx or simply abcdef. And Ids are not made by user, but by an administrator. So if he will enter a prefix say abc and want to generate 10 ids, Ajax will check for the highest prefix with that requested suffix in the database (with I am doing in the given snippet) and pop-up a div with a form showing registration for those 10 ids. So auto increment was no solution. Hope you understand my situation.
Thanks :)
Harpeet
这篇关于不使用try catch重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!