I have a table with 3 fields: id (auto_increment), name (string), x.
in my x field i want it to be kind of like a auto_increment but with letters and numbers being used. For example, if id field is 1, x will be "aaaa". if id is 2 x will be "aaab" and so on. the idea is that with for digits i could have a 14 million unique ids. can someone please help me out?

If you use BIGINT with auto_increment it will give you 9,223,372,036,854,775,807 unique values.

http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

It might save you some work trying to figure out triggers to just go with big int, unless you have another reason for the aaaa, aaab ids. If you have more than 9 million-billion records, you should probably switch to MSSQL

no thats not the problem. i can only have a 4 digits and i want to use they characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.
Lets just say its to number an invoice. For the client looking up invoice no. 9,223,372,036,854,775,807 just isn'tt practical. Max for digits. Thanks fo your suggestion anyway.

In that case I would use something like this. The chances of getting two matching are however many records in 14 million combinations. If you're worried about duplicates though, you could always run a quick query to verify the record number doesn't exist already.

function createRandomInvoicce() { 

    $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789"; 
    srand((double)microtime()*1000000); 
    $i = 0; 
    $pass = '' ; 

    while ($i <= 3) { 
        $num = rand() % 33; 
        $tmp = substr($chars, $num, 1); 
        $invoice= $invoice. $tmp; 
        $i++; 
    } 

    return $invoice; 

}

no it has to be done with a trigger in mysql? thanks anyway.

any body? something like client asking auto increment alphanumeric no

example ( ab100,ac100) somthing like this manner )?
please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.