Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6969089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:32:12+00:00 2026-05-27T16:32:12+00:00

I have a text file that I parse each month and insert the data

  • 0

I have a text file that I parse each month and insert the data into my database. The text file looks like this.

------------------------------------------------------------------------------------------------------------------------------------------------------------
BLK. NO 410              | 1   2|  3   4   5   6   7 | 8   9| 10  11  12  13  14 |15  16| 17  18  19  20  21 |22  23| 24  25  26  27  28 |29  30| 31   1   2
          BLK   88.35    |SA  SU| MO  TU  WE  TH  FR |SA  SU| MO  TU  WE  TH  FR |SA  SU| MO  TU  WE  TH  FR |SA  SU| MO  TU  WE  TH  FR |SA  SU| MO  TU  WE
          CR.   88.35           |194   / 159         |      |194   / 159         |      |194   / 159         |      |194   / 159         |      |239        
          OFF      14      :   : VER DFW TRC DFW   X   :   : VER DFW TRC DFW   X   :   : VER DFW TRC DFW   X   :   : VER DFW TRC DFW   X   :   : CUU DFW    
C/O 06.00 TAFB 216.15   194=/1410/1055/0740, 159=/0900/1700/1400, 239=/1845/1945/0155
EM3 25.55 ERD 42.00 EM4 20.40 
-----------------------------------------------------------------------------------------------------------------------------

This text file has from 100 to 300 of these records (we refer to it as a “line of flying”) and I use it to determine my flight schedule each month. I am parsing this file just fine but the company added a new wrinkle.

This “line” can be for a pilot or a flight attendant. Until recently each line could be for a captain or First Officer. But now some files have captain lines and first officer lines. The flight attendant file could have 1 or two flight attendant positions or more depending on the type of aircraft flown.

I need to create a new column in my database that reflects this new information. Once the lines are saved to the database, they are only searched, never updated again. I don’t want to add a new table just to keep track of this information. I want to add a new column to the existing table. Here is my strategy.

When I parse the text file, I will keep track of the positions available. If it is for Captain, I will save “CA” to the database. If it is first officer, I will save “FO”. If it is for both a captain and First officer, I will save “CAFO”. For flight attendants I will save a number “1” for 1 flight attendant poistion. For each additional poistion, I will just increment it one number. This would allow for expansion later if larger aiplanes required more flight attendant poistions.

So to recap, I will save one the following for each database record.

  • “CAFO”
  • “CA”
  • “FO”
  • “1”
  • “2”

Now I will need to access the database and retrieve these records for my web program. If a captain wants to retreive records He will want only captain lines which would be “CAFO” or “CA”. And just the opposite for first officers.
When I do the query, I found that I could use the mySQL command SUBSTRING to just grab the first 2 or last 2 characters.

for captain lines

SELECT Line_number,html_text FROM lines WHERE SUBSTRING(Crew_type,1,2)=”CA”

This would just get the first two beginning characters from the record and it would match both cases.
For First officers I start at the end of the string and grab last two characters.

SELECT Line_number,html_text FROM lines WHERE SUBSTRING(Crew_type,-2)=”FO”

For flight attendants I could compare the number.
If a flight attendant only wanted lines with 1 position.

SELECT Line_number,html_text FROM lines WHERE Crew_type = “1”

Or if they want all possible flight attendant positions

SELECT Line_number,html_text FROM lines WHERE Crew_type >= “1”

I would set the column type to ENUM with the values I listed above.

My question is there a better way to approach this problem? I will only be inserting once, but will be retreiving a lot. Will the SUBSTRING command slow down the queries too much?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:32:13+00:00Added an answer on May 27, 2026 at 4:32 pm
    SELECT Line_number,html_text FROM lines WHERE SUBSTRING(Crew_type,1,2)="CA"
    

    will be a performance killer, as it calculates the substring for all records, not only those used. You want

    SELECT Line_number,html_text FROM lines Crew_type in ("CA", "CAFO")
    

    Ditto for FO.

    So somewhere in your PHP iw would define

    $matches=array(
      'CA'=>'"CA","CAFO"',
      'FO'=>'"FO","CAFO"',
      'FA'=>'"1","2"'
    );
    

    and then use

    $match=$matches[$crew_type];
    $sql="SELECT Line_number,html_text FROM lines Crew_type in ($match)";
    

    with $crew_type being one of ‘CA’,’FO’,’FA’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file that looks a bit like: random text random text,
I have Text file that contains data separated with a comma , . How
I have a text file that I want to send over the network, this
I have a simple text file that is ~150mb. My code will read each
I have an app that loops through a fixed width text file, reads each
I have a class that parses in data from a comma delimited text file.
I'm reading positional records from a text file, for examle, it looks like this:
I have a file, the text format is like this: .640 .070 -.390 -.740
I have a text file that contains a long list of entries (one on
I have a text file that contains localized language strings that is currently encoded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.