php - Removing Duplicate Code -


i working on project , wanted on how approach problem , clean code , remove lot of duplication.

i have faq database table "id, user_id, faq_question, faq_text, sort_id". every time dynamic site created, have insert query creates site , inserts faq table default questions , answers want use.

    $insertfaq = array(         'user_id' => $user_id,         'faq_question' => 'default question',         'faq_text' => 'default answer',         'sort_id' => '1'     );       $db->insert('faq', $insertfaq); 

the sort_id there because have ability drag questions in different order , updates database , shows on website in new order.

now problem want have 10 default faq questions , answers created every website. if hundreds of sites in database, ton of records in faq database table pretty duplicated.

i know there has easier way it, thing throws me off sort_id because have same questions , answers sort them differently. , of course have ability add custom questions.

p.s. - how can add multiple questions/answers in above array posted?

as having multiple question in array posted in question, can have multi dimensional array:

$insertfaq = array(      0 =>array(     'user_id' => $user_id,     'faq_question' => 'default question',     'faq_text' => 'default answer',     'sort_id' => '1' ),  1 =>array(     'user_id' => $user_id,     'faq_question' => 'default question',     'faq_text' => 'default answer',     'sort_id' => '1' ),  2 => array(     'user_id' => $user_id,     'faq_question' => 'default question',     'faq_text' => 'default answer',     'sort_id' => '1' ) );` 

and on , son on.

as sorting - can create separate table hold sorting order, site id , question id.

id, faq_id, site_id, sort_order 

id new site created create new entry in table, , questions don't have repeat themselves, specifying order goes site.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -