0

i have multiple choice quiz script. after logged in each time the user can take 10 questions per quiz. at the end of the quiz results are saved into database .results are stored something like this:
id category_name user_id question_id answer_id time
1   php                   2               1                    3              40
2   php                   2               2                    3              40
3   php                   2               3                    2              40
how do i store quiz results somthing like this:
id category_name user_id question_id answer_id time
1   php                   2               1,2,3,4     3,3,3,4    30,25,45,43       

3
  • 5
    Can you show the code you tried already? Otherwise this sounds more like a request for paid coding.
    – RST
    Jan 10, 2016 at 14:11
  • That table really helped for an entire application..
    – user4412122
    Jan 10, 2016 at 14:11
  • You need to improve your question How to Ask
    – user4412122
    Jan 10, 2016 at 14:21

1 Answer 1

0

Storing data this way in the database is a bad idea, and you should reconsider your solution. It will be really difficult to make reports base on data like this in future.

However if you want to store data in this format in your db you want to serialize your data. In php you can take an array of results and serialize it. This will change it to be a string, which you can save in your database.

After that you can get your data back by pulling string back from the db and running unserialize command on it.

$data = array('1','2','3');
$serialized = serialize($data); 

// $serialized will equal:
// a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3";}
1
  • which is best way to store results? Jan 11, 2016 at 4:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.