10 Posts
kkdahl
7 years ago
10
Topic

Newbie allert! I appologize in advance :)

I have a field: 'prvtmat', where the value is a set of numbers, created by a Dynamic Select. It could for instance be: 21,20,19 

Those numbers correspond to the ID's of records in the #__tags table

I have the SQL Pack, and would like to, in the content form, have a field, that displays the values in the description column for ALL the ID's in field 'prvtmat' as one string.

I have tried dabbling with arrays, implode and what not. But beeing a complete newbie, getting nothing but errors.

Could you guys help with the sql?
Please. (pretty, pretty please)

Get a VIP membership
1283 Posts
Bucklash
7 years ago
1
Level 1

Hi

Just thinking out loud here while I'm walking my dog..,.

I would probably do a position override or variation (you choose)

and do a db query getting descriptions based upon the numbers stored prvtmat,

and then create your string that way

Make sense?

No doubt there are other options....

10 Posts
kkdahl
7 years ago
0
Level 2

Thanks

But like I wrote. I'm a big-time newbie. Do you have any links/references, since I haven't got any idea, as were to start.

4229 Posts
Kadministrator
7 years ago
7
Level 1

SQL pack won't work if you trying to use it in a form as $cck->get('fieldname') only works in content or list. In form you could only do it with javascript as form fields only get value when form is saved.

10 Posts
kkdahl
7 years ago
6
Level 2

Sorry that I was unclear
It is in content :)

4229 Posts
Kadministrator
7 years ago
5
Level 3

You will need to use code pack as value will be array if you have select with multiple values and sql can't work with arrays. 

In beforeStore event you can take value of your prvtmat field and loop trough it to get tags and cooencenate them to a single string, then push this value to your new field.

10 Posts
kkdahl
7 years ago
4
Level 4

So, you are telling me, that I have to buy the Code Pack too?
I thought that working with arrays was quite normal in sql - which the sql pack should let me? But no?

So there is no way to get different id's, defined as a comma-seperated field-value, "translated" to the corresponding values of another column, and shown in one field?

4229 Posts
Kadministrator
7 years ago
3
Level 5

If you have comma-seperated field-value, then it could work with sql only, but it will be complicated to get it working. Instead of using code fields you cna do it in an override as Buchlash suggested. 

10 Posts
kkdahl
7 years ago
2
Level 6

All right. I guess me and google will have a crack at it :-)

If anyone is in the mood for helping, then please don't hold back.

- I have field 'prvmat' whoose value is one or more numbers separatet by a comma

- those numbers are the ID's of column: description in table #__tags

- I would like to have a resulting sql (in an SQL Query-field) that gives me the content of all descriptions in a single string

1283 Posts
Bucklash
7 years ago
1
Level 7

Hi

Not tried this but reding the tutorial it seems legit.

Quote from there:

$cck->get('fieldname')->someProperty

This way you can get properties from other fields in the same content type e.g. 

value, you can also use alternative syntax $cck->getValue('fieldname'). 

This ONLY works when SQL "as field" is used in the content or list view. 

See last 2 articles on  http://www.seblod.com/resources/manuals/designer/overriding-a-position for details. *
SELECT CONCAT(' ,', description) FROM #__tags WHERE id IN ($cck->getValue('prvtmat'))

Something like that....

1283 Posts
Bucklash
7 years ago
0
Level 8

Hi

Not tested this either, but if doing a position override then

could add an sql query in the php file for your override.

Joomla syntax examples here 

Override would be like this:

template_name/positions/my_cool_override/my_cool_override.php

In your view (content view probably) select the position override for the appropriate position

<?php
/**
* @version 			SEBLOD 3.x Core
* @package			SEBLOD (App Builder & CCK) // SEBLOD nano (Form Builder)
* @url				http://www.seblod.com
* @editor			Octopoos - www.octopoos.com
* @copyright		Copyright (C) 2009 - 2016 SEBLOD. All Rights Reserved.
* @license 			GNU General Public License version 2 or later; see _LICENSE.php
**/

defined( '_JEXEC' ) or die;

$value = $cck->getValue('prvtmat');

$db = JFactory::getDbo();

$query = $db->getQuery(true);

$query->select('description'); // <- could do concat here

$query->from($db->quoteName('#__tags'));
$query->where($db->quoteName('id').' IN ('.$db->quote($value).')');

// Reset the query using our newly populated query object.
$db->setQuery($query);

// load values as indexed array
$descriptions = $db->loadColumn();

// separate the descriptions with a comma and a space
$descriptions = implode(', ', $descriptions);

echo $descriptions;
Get a VIP membership