Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
720 views
in Q2A Core by

Hello, 

is there any good way to import categories from csv file? 

Mine only idea was by INSERT to database => _categories

INSERT INTO `_categories`(`categoryid`, `parentid`, `title`, `tags`, `content`, `qcount`, `position`, `backpath`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8])

but I'm not sure is this way is Ok. 

Can someone be so kind and confirm, if I will do such Insert I will not should have trouble with them?

Q2A version: 1.5.4

1 Answer

+1 vote
by

Your best best is to write a script which calls qa_db_category_create(...) from qa-db-admin.php

by
Ok thx for idea. And for confirm You suggest to write php script which immport data from csv files?
I am noob so is there any good webiste beside this one :) which will help me with this ?
by
Thanks for this answer - I was able to use it to check if categories existed and if not, add new categories from a given list... Here's my code - I hope it helps someone...

    require_once 'qa-include/qa-db-admin.php';
        $categories = array("History","Family","People","Places");

    // Create Categories   
    for($i = 0 ; $i < count($categories) ; $i++) {
        echo "Processing category $i $categories[$i] : ";
       
        $categories[$i] = strtolower(str_replace(' ', '-', $categories[$i]));
        //$categories[$i] = strtolower($categories[$i]);
       
        if (qa_db_read_one_value(qa_db_query_sub('SELECT categoryid FROM ^categories WHERE parentid<=># AND tags=$',NULL, $categories[$i]), true)) {
            echo $categories[$i] . " already exists <br/>";
        } else {
            $categoryid = qa_db_category_create(NULL, $categories[$i], $categories[$i]);
            echo "created successfully <br/>";
        }
    }
       
    echo "<b>Completed Category Creation<br/></b>";
...