I am working on a project and I just wanted to get some help on how to approach this problem and help clean up the code and remove a lot of duplication.
I have an FAQ database table with “id, user_id, faq_question, faq_text, sort_id“. Now every time a dynamic site is created, I have an insert query which creates the site and then also inserts into the FAQ table with the default questions and answers that I want to 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 is there because they have the ability to drag the questions in a different order and it updates the database and shows on the website in the new order.
Now the problem is that I want to have 10 default FAQ questions and answers that will be created for every website. If we get hundreds of sites in the database, that will be a ton of records in the FAQ database table which is pretty much all duplicated.
I know there has to be an easier way to do it, the only thing that throws me off is the sort_id because they could all have the same questions and answers but sort them differently. And then of course they have the ability to add custom questions.
P.S. – How can I add multiple questions/answers in the above array that I posted?
AS for having multiple question in the array you posted in the question, you can just have a multi dimensional array:
and so on and son on.
as for the sorting –
You can create a separate table that will just hold the sorting order, site id and question id.
Id a new site is created you just create a new entry for it in this table, and than the questions don’t have to repeat themselves, your only specifying what order goes to what site.