You're basically describing a transaction reference code. Presumably you don't want this to be sequential otherwise you wouldn't have asked, therefore I'd suggest the following:
1) Query any suitable PRNG (pseudo-random-number-generator) function from a reputable crypto library (openssl, etc.) for a new value
2) feed this value into a hash function (e.g. SHA-1, md5 etc.) - again, available from your crypto library
3) take the first n bytes of the resulting alphanumeric string (these strings are hexadecimal numbers) - say around 8-10 - too long a substring will be take more space in a database to key on and be prone to mis-quoting by customers calling support staff, whereas too short a string increases the probability of a 'hash collision' (i.e. a duplicate). Therefore it's worth being too long than too short.
4) use this 8-10 (or whatever you choose) substring to key your database and store all your required transaction information (product id, quantity, unit price, total price, customer id etc.) alongside it.
One thing I would say, irrespective of the above suggestion, is that if you're not clear on exactly what your system design is (which since you're asking this question you won't be), make sure to seek some professional review of your architecture, database model and associated code. It is very easy to make mistakes in this sort of software which could lead to a lot of headaches for you and your customers down the line.