[HELP ME] create product code using PHP??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drawan
Forum Newbie
Posts: 3
Joined: Fri Aug 20, 2010 11:26 am

[HELP ME] create product code using PHP??

Post by drawan »

I am from Indonesia
help me, how to create logic of product code in accordance with the product name using script PHP?
example :
input product name : Toshiba Dynabook SS2000 Japan Product Notebook
then saved, product code become TDSJPN001

so that each combination of initial letters + three-digit number

Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: [HELP ME] create product code using PHP??

Post by AbraCadaver »

You'll have to work out how you determine what the number is. If you already have the same product code that ends in 001, then you'll need to increment it, but I don't know where you have stored these:

Code: Select all

$name = 'Toshiba Dynabook SS2000 Japan Product Notebook';

$words = str_word_count($name, 1);

$code = '';

foreach($words as $word) {
	$code .= $word[0];
}
$code .= sprintf('%03s', 1);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
jaiswarvipin
Forum Commoner
Posts: 32
Joined: Sat Sep 12, 2009 3:43 pm
Location: India

Re: [HELP ME] create product code using PHP??

Post by jaiswarvipin »

Hi,
adding to above you can use the following as well

Code: Select all

$name = 'Toshiba Dynabook SS2000 Japan Product Notebook';
$nameArray = explode(" ",$name);
$name = "";
for($intCount = 0; $intCount < sizeof($nameArray) ; $intCount++)
	$name . = substr($nameArray,0,1);
above code only give you first Intilai of the String then not it's depending on your requriement .i.e. If you Number in sequeance then yo uneed to get any how the previuos number and if not then you can generate the random number of three degit usinf rand(3);
drawan
Forum Newbie
Posts: 3
Joined: Fri Aug 20, 2010 11:26 am

Re: [HELP ME] create product code using PHP??

Post by drawan »

@jaiswarvipin and @AbraCadaver
I apologize because I'm less familiar with PHP
so please guide?
Post Reply