You are here:  » Create multiple new categories for category mapping in one go (bulk - import)


Create multiple new categories for category mapping in one go (bulk - import)

Submitted by APZ215 on Wed, 2019-08-28 09:18 in

Hallo David,
I wondered if it is simply possible to create multiple new categories for category mapping in one go (bulk) instead of one by one.

WHY: I have a list of categories that i want to use
PAGE: www... admin/categories.php
SOMETHING LIKE: https://www.pricetapestry.com/node/3094 (dbmod.php)

Can it be done by a PhpMyAdmin import, or to a create .php that create those fields in the datbase something like node/3094?

And if it's not possible, I'll just do it one by one :)

Thanks greetings Arlo

Submitted by support on Wed, 2019-08-28 09:38

Hello Arlo,

Do you have the list of categories as a text file that you could save in /feeds/ e.g. categories.txt - just one category per line:

Category 1
Category 2
etc.

If that would be quicker than manually creating the entries let me know and I'll work out an import script for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by APZ215 on Wed, 2019-08-28 11:23

Hello David,

Question = Do you have the list of categories as a text?
Answer = yes that's the idea! Sounds great, and would be great for future websites :-)

Thanks & greetings Arlo

Submitted by support on Wed, 2019-08-28 11:50

Hi Arlo,

With the category list as feeds/categories.txt here's an import script (run from top level)

<?php
  
require("includes/common.php");
  
header("Content-Type: text/plain");
  
$filename "feeds/categories.txt";
  
$fp fopen($filename,"r") or die("Could not open ".$filename);
  while(
$category trim(fgets($fp)))
  {
    
$sql "SELECT id FROM `".$config_databaseTablePrefix."categories` WHERE name='".database_safe($category)."'";
    if (!
database_querySelect($sql,$rows))
    {
      print 
"Adding: ".$category."\n";
      
$sql "INSERT INTO `".$config_databaseTablePrefix."categories` SET name='".database_safe($category)."'";
      
database_queryModify($sql,$result);
    }
  }
  print 
"Done.";
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by APZ215 on Wed, 2019-08-28 13:29

Thank you David, That's wonderful and works perfect! Greetings Arlo