Suppose Table1 contains column orderid (not a key, although it's NOT NULL and unique). It contains 5-digit numbers. What's the best way to generate a php var $unique_var that is not in that column. What could be important, from 10% to 30% of 5-digit numbers are in the table (so generating a number and checking while (mysql_num_rows() ==0) {}
is not a best way to find one, are there any better solution for performance?).
Thank you.
If there is just 10-30% of numbers already taken - then it means that only 10-30% of queries will be performed at least twice. Which is not a big performance issue at all.
Otherwise - just create all-5-digit-numbers-list table (just 100k rows) and remove all that exist. When you need another random number - just pick one and delete.
我建议找到最大的数字(使用MAX()子句)并从那里开始。
Here are a couple of suggestions. Each has its drawbacks.
LIMIT = 1
and mark it used. This uses a lot of space.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.