- Posts: 57
COMMUNITY FORUM
[SOLVED] Execute a query with K2 Tools custom php
- Klaus Veliu
- Topic Author
- Offline
- Senior Member
Less
More
7 years 4 months ago #161831
by Klaus Veliu
Execute a query with K2 Tools custom php was created by Klaus Veliu
Hello,
I am trying to use the K2 Tools Module in custom code mode.
After searching for a good example how to run a query in the database and after that manipulate the result I got lost without no information found.
Can someone suggest me how can I do this, or linking a good article about this issue?!
Thank you!
I am trying to use the K2 Tools Module in custom code mode.
After searching for a good example how to run a query in the database and after that manipulate the result I got lost without no information found.
Can someone suggest me how can I do this, or linking a good article about this issue?!
Thank you!
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
- Offline
- Platinum Member
Less
More
- Posts: 15920
7 years 4 months ago #161870
by Krikor Boghossian
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Replied by Krikor Boghossian on topic Execute a query with K2 Tools custom php
What data are you looking to retrieve?
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Klaus Veliu
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 57
7 years 4 months ago #161872
by Klaus Veliu
Replied by Klaus Veliu on topic Execute a query with K2 Tools custom php
I was trying to access some custom tables that are created manually from me, the issue was solved using Sourcerer, but still would be good to have an example using K2 Tools.
-How to run a custom query
-How to manipulate the result
-How to output them in the module
Thank you for your time!
-How to run a custom query
-How to manipulate the result
-How to output them in the module
Thank you for your time!
Please Log in or Create an account to join the conversation.
- esedic
- Offline
- Senior Member
Less
More
- Posts: 50
7 years 4 months ago #161884
by esedic
Replied by esedic on topic Execute a query with K2 Tools custom php
If you want to query Joomla database you can use Joomla API:
docs.joomla.org/Selecting_data_using_JDatabase
For example, you want to retrieve titles of K2 articles in the Categories view you are currently viewing:
You must enable "Parse PHP code" parameter in the module.
Basically you can parse any kind of PHP code in the module, it's up to you.
For example, you want to retrieve titles of K2 articles in the Categories view you are currently viewing:
<?php
$id = JFactory::getApplication()->input->getInt('id');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('title'));
$query->from($db->quoteName('#__k2_items'));
$query->where($db->quoteName('catid')." = ".$db->quote($id));
$db->setQuery($query);
$result = $db->loadColumn();
foreach($result as $title) {
echo $title.'<br>';
}
?>
You must enable "Parse PHP code" parameter in the module.
Basically you can parse any kind of PHP code in the module, it's up to you.
Please Log in or Create an account to join the conversation.
- Klaus Veliu
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 57
7 years 4 months ago #161917
by Klaus Veliu
Replied by Klaus Veliu on topic Execute a query with K2 Tools custom php
Thank you esedic,
Hope this will help the other users of K2 Tools :)
Hope this will help the other users of K2 Tools :)
Please Log in or Create an account to join the conversation.