jDiction Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

jDiction 2.2.0 released. http://jdiction.org/downloads

Author Topic: Retrieving translated category by SQL  (Read 14096 times)

zigzo

  • Newbie
  • *
  • Posts: 11
    • View Profile
Retrieving translated category by SQL
« on: September 27, 2013, 11:11:57 am »

Hello,

I am using jDiction and Phoca Gallery and with the jdiction.xml in another thread I could translate the category names successfully. Thanks!

However, I got a problem when trying to write some codes to select categories from the category table.  When I use select title from the category table, it can only retrieve the original names. 
How can I get the translated titles according to my site language? Do I need to refer to the jdiction sql table in my code as well?   Thanks!
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1688
    • View Profile
Re: Retrieving translated category by SQL
« Reply #1 on: September 27, 2013, 02:25:10 pm »

No this is not needed, jdiction intercept your query and adds the table key to the select list. After this it translates it on the fly.

You should use jdatabasequery so this could work without problems.

show me your sql query + php code
Logged
Joomla! 5.0 Release Manager
Vote at JED

zigzo

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Retrieving translated category by SQL
« Reply #2 on: September 28, 2013, 09:58:49 am »

Hi, thanks for your reply.

Actually I'm using chronoforms to generate the DB query to select the id, title...etc. from _phocagallery_categories.  The title is translated using jdiction. 
I have attached the related php code.

Thanks for helping!!
 
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1688
    • View Profile
Re: Retrieving translated category by SQL
« Reply #3 on: September 28, 2013, 10:51:21 am »

Hmm is a bit hard to say... maybe its better you show me the db query. Use the joomla debugmode to show all queries.
Logged
Joomla! 5.0 Release Manager
Vote at JED

zigzo

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Retrieving translated category by SQL
« Reply #4 on: September 28, 2013, 11:22:13 am »

The query is like this:
SELECT `id`, `owner_id`, `title`, `userfolder`, `latitude`, `longitude`
  FROM `cwosjm_phocagallery_categories` AS `myCategory`
  WHERE  owner_id = 852

And then I refer to the 'title' field to display in dropdown box.
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1688
    • View Profile
Re: Retrieving translated category by SQL
« Reply #5 on: September 28, 2013, 11:59:18 am »

is this query from the debug view?

because jdiction didn't touched this query.

So its possible that it was unable to parse it.

could you try to execute the query by hand?

just copy this code to the index.php in the template folder
Code: [Select]
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select("id, owner_id, title, userfolder, latitude, longitude");
$query->from("#__phocagallery_categories AS myCategory");
$query->where("owner_id = 852");
$db->setQuery($query);
$x = $db->loadObjectList();
print_r($x);

this should be translated.

if this doesn't work then there is a bigger problem with the jdiction installation.

after that please the ` to all fields like in your query and try again.

if this sill works, use this code:
Code: [Select]
$db = JFactory::getDbo();
$query = "SELECT `id`, `owner_id`, `title`, `userfolder`, `latitude`, `longitude` FROM `cwosjm_phocagallery_categories` AS `myCategory` WHERE  owner_id = 852";
$db->setQuery($query);
$x = $db->loadObjectList();
print_r($x);
If this sill work then chronoforms does some unnice query string that couldn't be parsed by jdicion.
Logged
Joomla! 5.0 Release Manager
Vote at JED

zigzo

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Retrieving translated category by SQL
« Reply #6 on: September 28, 2013, 05:12:53 pm »

Thanks for your reply!
The 1st one works.  And when I added ` for all fields, it works too.

The 1-line query code doesn't work though.
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1688
    • View Profile
Re: Retrieving translated category by SQL
« Reply #7 on: September 28, 2013, 05:40:32 pm »

to things I made an error  at

"FROM `cwosjm_phocagallery_categories` AS `myCategory`"

this should be

"FROM `#__phocagallery_categories` AS `myCategory`"

also try this query without `
Logged
Joomla! 5.0 Release Manager
Vote at JED

zigzo

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Retrieving translated category by SQL
« Reply #8 on: September 28, 2013, 05:50:55 pm »

All of them work. So it must be some manipulation inside the chronoforms...

I have just tried your code for the sql query instead of the default chronoform action and it works now~

Thanks for your help!
Logged

Harald Leithner

  • Administrator
  • Hero Member
  • *****
  • Posts: 1688
    • View Profile
Re: Retrieving translated category by SQL
« Reply #9 on: September 28, 2013, 08:16:46 pm »

If you can life with it take the first version for performance reasons
Logged
Joomla! 5.0 Release Manager
Vote at JED

zigzo

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Retrieving translated category by SQL
« Reply #10 on: September 29, 2013, 11:35:39 am »

I see. Thanks a lot!!
Logged