views:

115

answers:

2

hi, first of all thanks for taking your time!

I'm a junior Dev, working with PHP + mysql.

My issue:

I'm saving data from a form to my database. From this form, there's only need to save the contacts: Name, phone number, address. But, it would be nice to have a small reference to the user answers.

Let's say for each question we've got a value betwee 1 and 4. Since there's no need to create a table just for it, because what's needed is just the personal contacts. I'm thinking of recording each question/answer, as a letter and its correspondent value.

Example (A2, B1, C5, D3, etc).

My question is:

Is there a format I could afterwards, handle easily ? Convert to array (string to array) in case the client change ideas, and ask this data, placed in table columns ? Just to prevent this situation!

Example,

From (A2, B1, C5 ) to array( "A" => "1", "B" => "1", "C" => "5" )

    • For now I guess, Regex is the answer, but it's allways hard to figure it out and I'm allways getting in troubles =)

Thanks!

A: 

Take a look at str_split() or explode().

Danten
+1  A: 

If you're not going to properly model this in a relational way, then just go with a serialized object.

PHP's serialize()/unserialize() (faster, more flexibile) or json_encode()/json_decode() (more human readable, more portable) will work just fine.

Peter Bailey