Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert data to a code 1

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i am trying to write some code to generate a product code, then on another page i want to type the product code back in to then decode to the right data.

I have 3 fields, Product_ID, Ref, Price...

Product_ID can be values of 1 to 17
Ref is a 5 digit number

I want to convert a price to a letter system such as..

0 = A
1 = B
2 = C
etc..

And have the following positions in the code...

Th H T U D

Which is Thousands, Hundreds, Tens, Units and Decimals

So if i have the following data..

Product_ID = 3
Ref = 12765
Price = 10.50

I want the code to look like...

0312765AABAF

Hope all this makes sence!

Please can anyone help!

Many thanks,

Brian
 
Grief that was fast! Your a genious!!!

How can i take a part this code again and put back into variables??

Kindest thanks

Brian!
 
Hi

Code:
if (preg_match('/^(\d{2})(\d{5})(\w{5})$/',$strangecode,$match)) {
  $Product_ID=intval($match[1]);
  $Ref=intval($match[2]);
  $Price=intval(strtr($match[3],'ABCDEFGHIJ','0123456789'))/10;
}

Feherke.
 
Thank you so much, have been able to get this working in a test!!

Kindest regards,

Brian
 
Dont suppose anyone knows how i could tempory use an excel spread sheet to record this information and show the decode? I need to use this in the mean time until the website is fully operational.

Ie.

First column = The strangecode
Second Column = Product ID
Third Column = Ref
Fouth Column = Price

Many thanks,
Brian
 
Hi

I have no Excel.

But if you accept an open source solution, here is an OpenOffice.org Calc spreadsheet with the conversions.

[small]( Note : files are deleted from SaveFile after 30 day of inactivity. )[/small]

Feherke.
 
why not use sqlite instead? or at worst just a csv file on the webserver?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top