Keyword

Is it possible to mass add a tag in all items of one category?!

More
14 years 3 weeks ago #97152 by Andrea Vigato
sorry, don't know how to delete those boxes in the code :O

 

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
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97153 by B_Dark
$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.

  • B_Dark
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97154 by B_Dark
Error
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 =& 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.

More
14 years 3 weeks ago #97155 by Andrea Vigato
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 =& 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
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97156 by B_Dark
  and I  started  thinking that is for php because I had never seen such a code for sql again :P

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 =& 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
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97157 by B_Dark
i copy the code of index.php and i put your code in the and of code?

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
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97158 by B_Dark
+ and if i want to put more of one tags in items of one category a make this$second_query = "INSERT INTO jos_k2_tags_xref VALUES ($start_id, 40; 13; 41;, $column[$i])";?

Please Log in or Create an account to join the conversation.

More
14 years 3 weeks ago #97159 by Andrea Vigato
no, if you want you just put my code in the first lines of your index.php (it's not important the file, just let something read the code and do the query :) the important is that is a php file)....you don't have to delete nothing, just put the code in a page and load the page.

 

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
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97160 by B_Dark
Fatal error: Class 'JFactory' not found in /home/promo/public_html/myweb.com/code.php on line 13

Please Log in or Create an account to join the conversation.

More
14 years 3 weeks ago #97161 by Andrea Vigato
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.

  • B_Dark
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97162 by B_Dark
in index.php or in new copy with different name the same error "a normal general php->DB connection" like?

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.

More
14 years 3 weeks ago #97163 by Andrea Vigato
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’);
Attachments:

Please Log in or Create an account to join the conversation.

  • B_Dark
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97164 by B_Dark
I'm a little confused:(( in index.php of template or the index.php of joomla site?

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.

More
14 years 3 weeks ago #97165 by Andrea Vigato
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.

  • B_Dark
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97166 by B_Dark
they give me a blank page

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.

More
14 years 3 weeks ago #97167 by Andrea Vigato
<?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.

  • B_Dark
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97168 by B_Dark
Fatal error: Class 'JFactory' not found in /home/promo/public_html/myweb.com/index.php on line 13



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.

More
14 years 3 weeks ago #97169 by Andrea Vigato
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.

  • B_Dark
  • B_Dark's Avatar Topic Author
  • Offline
  • Premium Member
More
14 years 3 weeks ago #97170 by B_Dark
different version? i use the last of 1.5

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.

More
14 years 3 weeks ago #97171 by Andrea Vigato
just thinking :) really don't know how you cannot load JFactory class in the index.php....if you want just pass me the 2 tables (jos_k2_tags_xref and jos_k2_items) and i will do it in 3 hour cause i'm out now....otherwise really don't know sorry :( i repeat, the code is right for me...works perfect...

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum