| | |
Id create in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 148
Reputation:
Solved Threads: 25
Assuming you cant or dont want to use an auto-incrementing value, I would suggest maybe using a UUID if length is not a concern. PHP lacks direct support, but they can be generated automatically via mysql. http://dev.mysql.com/doc/refman/5.0/...#function_uuid
Although personally i think they are atrocious to look at and have to work with.
Although personally i think they are atrocious to look at and have to work with.
I would really discourage this - use an autoincrement integer (or mediumint - depending on the max no. of products that you envisage your database holding). I image that you are using a database model with primary/foreign key relationships (indexing). Text indexing is slooooooow. If your proposed text primary key is randomly generated, it would have no bearing on the identification of the product (ie no relationship to the name of the product), so I can't see the rationale behind this. However, I'm no major expert.
•
•
Join Date: Sep 2008
Posts: 138
Reputation:
Solved Threads: 0
And I had a code like this...
Will it cause repetition in any condition ????
PHP Syntax (Toggle Plain Text)
$string = md5(microtime() * mktime()); $id = substr($string,0,6);
Will it cause repetition in any condition ????
If you were using the full MD5 hash then there would be a small chance for repition, however since you are only using the first 6 characters, this chance is greater.
You must the uniqe product ID be in the format you suggest? Would it not make more sense to have an 'id' column which is an auto-increment and also have a 'product_id' where you can put your fancy ID without fear of having duplicates.
If you really wanted to you could then index the product_id column and seacrh it, but this would not be the best idea as the IDs may not be unique..
You must the uniqe product ID be in the format you suggest? Would it not make more sense to have an 'id' column which is an auto-increment and also have a 'product_id' where you can put your fancy ID without fear of having duplicates.
If you really wanted to you could then index the product_id column and seacrh it, but this would not be the best idea as the IDs may not be unique..
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
•
•
Join Date: May 2008
Posts: 232
Reputation:
Solved Threads: 19
Try using time(), it produces a number value that is different every second and would never repeat. You could also add a rand() command to add a random number on the end so even if two people created a product at exactly the same time there would be a slim chance that it would be the same;
if you wanted to be almost certain not to create any duplicates you could increase the second number in the rand() command
Hope this helps,
Regards,
Sam Rudge
PHP Syntax (Toggle Plain Text)
$ID = time() . rand(0,9); //Unix Time & A random number between 0 and 9
Hope this helps,
Regards,
Sam Rudge
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
![]() |
Similar Threads
- How To Create A Free Web Host (PHP)
- WANTED : PHP/Mysql programmer (US time zone) (Web Development Job Offers)
- php drop down menu to search multiple sql tables (PHP)
- php/mysql coder for paid job (Web Development Job Offers)
- PHP .htaccess form (PHP)
- phpBB to php-nuke integration help (PHP)
- php login form (PHP)
- php mysql help (PHP)
- How ti detect whether PHP is installed or not? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Shopping cart
- Next Thread: General Date Convertor and Calculator (Simple)
| Thread Tools | Search this Thread |
# 5.2.10 action address apache api array auto autoincrement beginner binary broken cakephp checkbox class classes cms code cron curl database date dehasher destroy display dissertation domain dynamic echo echo$_get[x]changingitintovariable... email error errorlog fatalerror file files folder form forms function functions google href htaccess html if-else image images include insert ip javascript joomla legislation limit link load login mail masterthesis menu mlm multiple mysql mysqlquery oop open paypal pdf persist php popup problem query radio random record recursion remote script search server sessions sms sockets source space sql syntax system table tutorial update upload url validator variable video web youtube





