Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can kinda fudge it, but I would totally recommend adding another column. Here's how I'd do it with PHP.</p> <pre><code>// do your insert // Retrieve last insert id $orderId = mysql_insert_id(); // get the current timestamp $time = time(); // Intersperse the $orderId into the $time to get a new "hash" $orderId = explode("", (string)$orderId); $time = explode("", (string)$time); $orderIdLength = sizeof($orderId); $newOrderId = ""; for ($i = 0; $i &lt; $orderIdLength; ++$i) { $newOrderId .= $orderId[$i] . $time[$i]; } $newOrderId = (int)$newOrderId; </code></pre> <p>So, if your actual order id is 489, and the current timestamp is 1300778794, you end up getting an order id that looks like 418390. If your customer then uses that order id for anything, you simply have to break it back down:</p> <pre><code>$newOrderId = explode("", (string)$newOrderId); $length = sizeof($newOrderId); $oldOrderId = ""; for ($i = 0; $i &lt; $length; $i = $i + 2) { $oldOrderId .= $newOrderId[$i]; } $oldOrderId = (int)$oldOrderId; </code></pre> <p>This isn't a very sophisticated approach and isn't 100% fool-proof. But for the sake of gently obfuscating your order ids, I think it does the job sufficiently.</p> <p><em>Edit:</em> just as a quick aside, you can use some other method of generating some semi-random number for padding the id other than <code>time()</code>. For example, you could do <code>rand(pow(10, log10($orderId)), pow(10, log10($orderId)+1))</code>, which would always return some random number that's the same length as the orderId.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload