0

OK, this may sound like an odd question so first let me lay out the basic situation:

At our company we're using a ticketsystem. This system has a FAQ dbase. I can't change the structure of the database in any way because we would have to change the ticketsystem to cope with that change and that is not an option.

So with that out of the way...
Because there is no seperate field available we add a chapter number to the title of every item to have a sort of index.

So you'd get something like this:

1 start
1.1 some subchapter
2 new chapter
3 another chapter
3.1 sub of chapter
3.1.1 sub sub chapter

etc..

Offcourse with a nifty regex it's easy to extra the chapter part from the string. But the next step would be to make it easy to find the corresponding subchapters based on the parent chapter. Easiest way to make this searchable without a database would be a multidimensional array, right?

So you would get this:

array( 3 => array( 
              'item' => 'data', 1 => array('item', 2 = array() ) ) )  etc...

What I've done now is to create an array of chapter indexes ( [3,1,1] in the case of 3.1.1 ) and because I know the there are always between 1 and 3 items in this array I made a switch based on the array length and then did this:

$array[$index[0]][$index[1]]['item'] = $content;

But I feel this is a very dirty and unlfexible way of doing this. Normally I'd vote for changing the database structure no matter what, but without that option I'm unsure what the best method would be.

Any help would be great!

EDIT: Added my comment below for better readability

Titles are one line indeed, but that part I have working with a regex to extract the chapter part. So that's working.

What I basicly build is a form that uses the array of indexes to build a list of checkboxes for each chapter or chapterpart. But I don't want to search through the array and compare keys to find subchapters. So if I'd choose 3.1 I'd check 3.1.1, 3.1.2 and because the key starts with 3.1 I'd know to print it.

Faster would be to be able to do this:

Choose 3.1.1 => return $chapters[3][1][1]['item']

But that's only possible when I can build the initial array in that form.

2
  • are all titles one-line? is this on a single page only or there are multiple pages and you search based on those indexes? Commented Aug 20, 2012 at 12:35
  • Titles are one line indeed, but that part I have working with a regex to extract the chapter part. So that's working. What I basicly build is a form that uses the array of indexes to build a list of checkboxes for each chapter or chapterpart. But I don't want to search through the array and compare keys to find subchapters. So if I'd choose 3.1 I'd check 3.1.1, 3.1.2 and because the key starts with 3.1 I'd know to print it. Faster would be to be able to do this: Choose 3.1.1 => return $chapters[3][1][1]['item'] But that's only possible when I can build the initial array in that form. Commented Aug 22, 2012 at 9:59

1 Answer 1

1

The situation has changed and we are creating a second database structure with a better setup to handle the situation above.

Basicly we use that to both print a well formatted PDF as well as pushing the info in the FAQ of the ticket system.

This gives us the best of both world and thus solving the issue above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.