How do I generate numbers that are not duplicated when processing a list in while?

while ($row = mysqli_fetch_array($aa)){

      $public_order_id = date("Ymd", time()).rand(1,999999);

because there will be more than one br in an instant.
my current idiotic approach is to use rand.
, but 1999999 still has a chance to reproduce, because it uses while to generate a list!
so maybe the first generation will be 222, and the 20th will have a chance of 222!
because it is not useful to use time (), the time will be exactly the same, too fast
unless the generated list exceeds 20, the number of digits may be + 1
and it has to be compared with the database. If there is a duplicate, go back to the previous step and reproduce it.?
I have an ID that can be viewed by programmers, so I use AUTO_INCREMENT
but now I want to generate
that I want people to see. Do you want to think about a better way?

Mar.28,2021

I think it's enough for you to use date ('Ymd'). Uniqid (). Rand (10000 Ymd'). Uniqid (). Rand (999999)


1: uuid
2: use smaller microseconds

// 
for ($i = 0; $i < 10000; PP $
    
    do {
        $time = str_replace('.', '', microtime(true));
        // 
        $key = $time . str_pad(1, 9999, STR_PAD_LEFT);
        
        // 
        if () {
            // 
            break;
        }
        
        //  
    } while(true);
    
}

the order number can be spelled with the user ID (user_id) and the number of user orders.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e49856-65357.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e49856-65357.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?