Keyword

SOLVED --- Comparing tags with item title (dash-problem)

  • Bam Bam
  • Bam Bam's Avatar Topic Author
  • Offline
  • Senior Member
More
9 years 3 days ago - 9 years 1 day ago #154271 by Bam Bam
Hey everybody,

I have another little problem and hope you can help me to solve this.
I'd like to compare the tags setted in an article with the item title of another article. E.g. article1 has tag firm1, this article should show up under the article with the title "firm1". In my override it works - except there is a dash in the item title. K2 strips out the dash in the tags. Right now I'm using a mySQL-query and I don't know how I can strip the dash in the item title out. My code looks as follows:
$db->setQuery("SELECT c.`id`, c.`name`, ca.`id`, ca.`title`, ca.`introtext`, ca.`extra_fields`, ca.`alias` FROM #__k2_items AS ca, #__k2_tags AS c WHERE (c.`id` = '$tag_item->id') AND (c.`name` = ca.`title`)"  			);
As you can see I get the id of the tag and compare the name with the item title --- but the dashes...?! :(
Any suggestions?

Kind regards
Matthew.
Last edit: 9 years 1 day ago by Bam Bam.

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

  • JoomlaWorks Support Team
  • JoomlaWorks Support Team's Avatar
  • Offline
  • Elite Member
More
9 years 2 days ago #154288 by JoomlaWorks Support Team
Replied by JoomlaWorks Support Team on topic Comparing tags with item title (dash-problem)
Hello,
I am sorry but I do not understand where this dash appears ? Is it in the ca.`title` at your mysql query ?

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

  • Bam Bam
  • Bam Bam's Avatar Topic Author
  • Offline
  • Senior Member
More
9 years 2 days ago - 9 years 2 days ago #154297 by Bam Bam
Replied by Bam Bam on topic Comparing tags with item title (dash-problem)
Correct. The firm name (ca.`title`) is e.g. "We - from outer space". In the tags the dash is stripped, so the firm name (c.`name`) is "We from outer space". Because of this the query does not recognize that it is the same firm name, without dash. So no array is generated.
Do you know what I mean?
Last edit: 9 years 2 days ago by Bam Bam.

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

  • JoomlaWorks Support Team
  • JoomlaWorks Support Team's Avatar
  • Offline
  • Elite Member
More
9 years 1 day ago - 9 years 1 day ago #154314 by JoomlaWorks Support Team
Replied by JoomlaWorks Support Team on topic Comparing tags with item title (dash-problem)
You can use the mysql REPLACE function to replace the dashes

dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_replace

Below I provide an example with your database query
SELECT c.`id`, c.`name`, ca.`id`, ca.`title`, ca.`introtext`, ca.`extra_fields`, ca.`alias` FROM #__k2_items AS ca, #__k2_tags AS c WHERE (c.`id` = 5) AND (c.`name` = REPLACE(ca.`title`, '-', ' '))
Last edit: 9 years 1 day ago by JoomlaWorks Support Team.

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

  • Bam Bam
  • Bam Bam's Avatar Topic Author
  • Offline
  • Senior Member
More
9 years 1 day ago #154316 by Bam Bam
Replied by Bam Bam on topic Comparing tags with item title (dash-problem)
YES YES YES!!! Thank you so much. I tried the REPLACE-function, but I did not really know how to use this. *happy* :)

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


Powered by Kunena Forum