- Posts: 50
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- Is it possible to mass add a tag in all items of one category?!
Is it possible to mass add a tag in all items of one category?!
- Andrea Vigato
-
- Offline
- Senior Member
just copy it row by row and use it....remember to delete the starter // in each line
Andrea Vigato said:
Ok,
/******************************************************/
// $db =& JFactory::getDBO();
// $first_query = "SELECT ID FROM jos_k2_items WHERE catid=8";
// $db->setQuery($first_query);
// $counter = $db->getNumRows(); // we get the number of rows created, cycle value
// $column= $db->loadResultArray(); // load all the result in a var, then access the values with the index of the for
// $start_id = 44; // or the last ID value in the jos_k2_tags_xref
// for($i=0; $i<=$counter; $i++) {
// $second_query = "INSERT INTO jos_k2_tags_xref VALUES ($start_id, 40, $column[$i])";
// $db->setQuery($second_query);
// $start_id++;
// }[/code]
[/code]
/********************************/[/code][/code]
the INSERT INTO query not have the SELECT FROM WHERE.
I think it's ok, maybe check it for some operators error...
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String @ 5 STR: =& SQL: $db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();$db =& JFactory::getDBO();
SQL query:
$db =& JFactory::getDBO();
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$db =&amp; JFactory::getDBO()' at line 1
B_Dark said:
$db =& JFactory::getDBO(); $first_query = "SELECT ID FROM jos_k2_items WHERE catid=8"; $db->setQuery($first_query);$counter = $db->getNumRows(); $column= $db->loadResultArray(); $start_id = 44;for($i=0; $i<=$counter; $i++) {$second_query = "INSERT INTO jos_k2_tags_xref VALUES ($start_id, 40, $column[$i])"; $db->setQuery($second_query); $start_id++;}right?
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$db =&amp; JFactory::getDBO()' at line 1
the $db line is not into the query, so how it's possible mysql said that?
are you using the code from phpmyadmin maybe?
What i wrote down is to use in a php file, just load the file and then it will start the queries directly from PHP.
You cannot do it from something else because you need to save variables and cycle.
If you want you can pass me the DB and i will do it for you directly now, i'm actually in free time :) or, you have to copy the code in a php file (also the index.php) and just load it. After that remove the code.
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
hmm, what are you using to do the code? what file?
MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '$db =&amp; JFactory::getDBO()' at line 1
the $db line is not into the query, so how it's possible mysql said that?
are you using the code from phpmyadmin maybe?
What i wrote down is to use in a php file, just load the file and then it will start the queries directly from PHP.
You cannot do it from something else because you need to save variables and cycle.
If you want you can pass me the DB and i will do it for you directly now, i'm actually in free time :) or, you have to copy the code in a php file (also the index.php) and just load it. After that remove the code.
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
r, you have to copy the code in a php file (also the index.php) and just load it. After that remove the code.
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
To put more tags i think you have to repeat the code with a different tagID....as i know (don't have the k2 DB right now) it expect just one value, so you cannot use 40;13;41 but just a number.
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
Anyway use JFactory or a normal general php->DB connection, just connect to your DB and do the query...i've tested in local and the code is perfect.
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
hmm..i got no problem to connect to JFactory....maybe you're using something different? It's a new file you've created now? Maybe you have to connect it to joomla and not just copy the code :) i think...
Anyway use JFactory or a normal general php->DB connection, just connect to your DB and do the query...i've tested in local and the code is perfect.
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
www.php.net/manual/en/function.mysql-connect.php
php.net/manual/en/function.mysql-query.php
For JFactory:
docs.joomla.org/JFactory
I've uploaded two screenshots, one it's my index.php loading the DB and the other is the source view of the echo of $db....
JFactory is always loaded while you stay in joomla MVC, it's impossible you cannot load it in the index.php i think...you have two way to load a framework class:
require('libraries/joomla/factory.php');
jimport(‘joomla.factory’);
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
For general php:
www.php.net/manual/en/function.mysql-connect.php
php.net/manual/en/function.mysql-query.php
For JFactory:
docs.joomla.org/JFactory
I've uploaded two screenshots, one it's my index.php loading the DB and the other is the source view of the echo of $db....
JFactory is always loaded while you stay in joomla MVC, it's impossible you cannot load it in the index.php i think...you have two way to load a framework class:
require('libraries/joomla/factory.php');
jimport(‘joomla.factory’);
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
You have your joomla files with administrator, components, modules, templates no? In your templates dir enter your default template folder (rhuk_milkyway, atomic or whatever is) and you will see an index.php (default joomla load this one for first page).
Edit the index, after the "defined('_JEXEC') or die ..." put the code i gave you (like in the code_index.png screenshot), then just load it in browser.
If it's all correct you will see in phpmyadmin, in your DB, in the jos_k2_tags_xref that has been inserted a lot of new field.
After that just remove the code from the index and it's ok, all of your item in category now have the related tag.
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
the index.php that is first loaded when you reach your website, so i think the index.php of the template.
You have your joomla files with administrator, components, modules, templates no? In your templates dir enter your default template folder (rhuk_milkyway, atomic or whatever is) and you will see an index.php (default joomla load this one for first page).
Edit the index, after the "defined('_JEXEC') or die ..." put the code i gave you (like in the code_index.png screenshot), then just load it in browser.
If it's all correct you will see in phpmyadmin, in your DB, in the jos_k2_tags_xref that has been inserted a lot of new field.
After that just remove the code from the index and it's ok, all of your item in category now have the related tag.
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
$first_query = "SELECT id FROM jos_k2_items WHERE catid=8";
$db->setQuery($first_query);
$db->query();
$counter = $db->getNumRows();
$column= $db->loadResultArray();
$start_id = 44;
for($i==0; $i<=$counter; $i++) {
$second_query = "INSERT INTO jos_k2_tags_xref VALUES ($start_id, 40, $column[$i])";
$db->setQuery($second_query);
$db->query();
$start_id++;
}
?>
try this new code, goes perfectly to me...
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
<?php $db =& JFactory::getDBO(); $first_query = "SELECT id FROM jos_k2_items WHERE catid=8";
$db->setQuery($first_query);
$db->query();
$counter = $db->getNumRows();
$column= $db->loadResultArray();
$start_id = 44;
for($i==0; $i<=$counter; $i++) {
$second_query = "INSERT INTO jos_k2_tags_xref VALUES ($start_id, 40, $column[$i])";
$db->setQuery($second_query);
$db->query();
$start_id++;
}
?>
try this new code, goes perfectly to me...
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
You just have to connect to the DB, i always use "$db =& JFactory::getDBO();"...really don't know how it can give you the error i'm sorry....maybe you're using something different, a different version of joomla or whatever don't know...
Please Log in or Create an account to join the conversation.
- B_Dark
-
Topic Author
- Offline
- Premium Member
- Posts: 126
Andrea Vigato said:
well, really i don't know what's the problem....the query and the code to add the tagID to the items in a certain category is correct.
You just have to connect to the DB, i always use "$db =& JFactory::getDBO();"...really don't know how it can give you the error i'm sorry....maybe you're using something different, a different version of joomla or whatever don't know...
Please Log in or Create an account to join the conversation.
- Andrea Vigato
-
- Offline
- Senior Member
- Posts: 50
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- Is it possible to mass add a tag in all items of one category?!