Jump to content

Recommended Posts

Hi everyone, I’ve created a code ($item1)

What I’m trying to do is read certain numbers of the code to tell my site what kind of membership to create.

 

For instance

12****** is the length of service

**00**** is account type, and so on

 

My code doesn’t work.  Any suggestions would be greatly appreciated

 

$item1 = 12001102;

if ( $item1 == 12****** ) {
echo "you have 12 months";
} else {
echo "don’t do anything";
}

Link to comment
https://forums.phpfreaks.com/topic/84081-solved-product-code-interpreting/
Share on other sites

You will need away to break up the number. Therefore when you create the number seperate each bit on infor with a "-" then you could do something like this

 

 

$pizza  = "12-00-00-00";
$pieces = explode("-", $pizza);
echo $pieces[0]; // 12
echo $pieces[1]; // 00

 

look at explode in the manual

You dont have to separate by slashes/dashes. You could either use the substr() funcion , or rebuild the new string by accessing the characters individually:

 

<?php
$num = '12001102';
$length = $num[0].$num[1];//
$account_type = substr($num,2,2);
echo $length.'<br />';;
echo $account_type;
?>

 

That said, separating by shashes would probably be better - what happens if one of thse suddently needs to be 3 digits long. If you separate by shashes, it wouldn't be a problem.

 

Finally, if this data is coming from a database table, you'd be better off storing each piece of information individually. What happens when you suddenly want to see all the items where the account type is 00? If could be done with the way you're storing information at present, but it would be easier if you stored each piece separately.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.