Datafeedr Support Forums

Datafeedr Support Forums (http://www.datafeedr.com/forums/index.php)
-   Tips, Tricks & Tutorials (http://www.datafeedr.com/forums/forumdisplay.php?f=66)
-   -   Multiple category and sub-category insertion (http://www.datafeedr.com/forums/showthread.php?t=5730)

seovisions November 21st, 2011 05:21 PM

Multiple category and sub-category insertion
 
Hello,

I have discovered, quite by accident, that adding categories and sub-categories makes use of a delimiter for multiple entries:

PHP Code:

category1/category2/category3 

This is partially useful in that it shows that datafeedr allows for multiple insertion of category taxonomies. However, it loses it's usefulness because of what this particular delimiter actually does:

PHP Code:

Main Category
Main Category 
category1
Main Category 
category1 category2
Main Category 
category1 category2 category3 

Which, essentially, nests each category followed by "/" into a sub-category of the one right before it. or:

PHP Code:

category1
-category2
--category3 

I've tried all the usual delimiter types to see if I could add several sub-categories under a main category in a single insertion. Such as

PHP Code:

/, |, \, :, `, ~, & 

of which only one has any result.

So my tip is the above, and my question is this:

Is there a delimiter in place to allow for multiple entries when adding categories and subcategories?

johnpo November 21st, 2011 06:55 PM

Yes the slash allows for one under one under and so on, unfortunately doesn't simply allow all one under so have to move them, but is still quicker than typing them all in.

Eric November 21st, 2011 08:53 PM

Quote:

Originally Posted by seovisions (Post 26237)
Is there a delimiter in place to allow for multiple entries when adding categories and subcategories?

Not currently.

seovisions November 22nd, 2011 12:50 AM

perhaps you could add a delimiter. I am not entirely sure what you programmed everything in, nor how difficult it would be to add a delimiter.

Maybe a simple php explode on | would work along with a basic foreach with the SQL insert.

ie:
PHP Code:

$parent $_POST['parent'];
$add_category explode('|'$_POST['category_string']);

if(
count($add_category) > 0){

//multiple entries to add
foreach($add_category as $value){
try{
mysql_query("UPDATE table SET category = $value WHERE cat_parent = $parent );
}catch(Exception 
$e){
echo 'Exception caught: ',  
$e->getMessage(), "\n";
}

}

}else{

//it's a single entry
try{
mysql_query("
UPDATE table SET category $value WHERE cat_parent $parent );
}catch(
Exception $e){
echo 
'Exception caught: ',  $e->getMessage(), "\n";
}



You would, of course, fix it to fit the tables used, error checking, etc.

seovisions November 22nd, 2011 01:04 AM

preg_split() is another method to use if you want more control as well as preg_match_all().

Point is..lots of ways to do it. explode can be more memory intensive then the above two options.


All times are GMT -5. The time now is 12:43 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.