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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

goal: display data from database referenced by inputted data

Status
Not open for further replies.

russizm

IS-IT--Management
Apr 19, 2010
5
US
Hello all, I am not a programmer but I can wade my way through getting what I want to accomplished usually but I'm having trouble trying to describe what I'm looking to do in php terminology.

I'd like to create a page that has a submission form for a string with specific amount of characters (10) then split(explode?) this string into 5 parts.

For Example: If the submitted string is "KPOISDD011" then I want it split like K | PO | ISD | D | 001 and then for each item refer to a database and grab another string of text that corresponds for each item and then display it.

In this example K = Kent, PO = Professional Office, ISD = Information Services Department, D = Desktop, 011 = 011

I understand if I want to explode this string then I need a separator but not sure how to go about doing this. I feel like this is basic PHP but just a little bit more advanced than what I can understand. Any help would be much appreciated.
 
You don't "need" a separator, but it would be easier if you had one.

If the Splits are always the same number of characters: 1 char | 2 chars | 3 chars | 1 char | 3 chars then you can loop through the provided string, and take out each section you need by the amount of characters it requires.

You can use the subtr() function to get the sections you need.

You could even just address them directly in the string:

Code:
$mystring="KPOISDD011";

echo $mystring[0]; /* Output: K */

echo $mystring[1] . $mystring[2]; /* Output: PO */
etc...


If the splits are not ALWAYS the same number of characters, then yes you would need some type of delimiter such as entering the string as: K-PO-ISD-D-011 The delimiter in this case is a hyphen, it can be a slash, a comma whatever character you want that does not appear inside the pieces you want.


Then you could use the explode() function to get the pieces of the string into an array.

Code:
$mystring="K-PO-ISD-D-011" ;
$mypieces=explode("[red]-[/red]",$mystring);
 echo $mypieces[0]; /* Output: K */
 echo $mypieces[1]; /* Output: PO */

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
yes as of right now the splits will be the same for everything that is submitted. Thanks for the response!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top