332 Posts
Kenneth
9 years ago
Topic

Hi,

I've setup a dynamic select field in my content type to select users. With the field I save the ID of the user as value.

With this value I want to run a SQL query to a certain table and to get values from several of the fields in the table matching the user ID selected in the dynamic select field.

How can I do this? I've found some posts in the old forum but can't get it to work.

Get a Book for SEBLOD
9 years ago
0
Level 1

Hi kenneth,

The functionning you decsribed does not correspond to the phylosophy of SEBLOD.

The fields values you want to display are created using from which form/content type? Can you explain more?

Regards,
Mehdi

332 Posts
Kenneth
9 years ago
7
Level 1

Sure.

It's a news site. And there is always one author, and that author ID get's saved to art_created_by.

Often there are co-authors, who contribute and we need to get them listed as well.

I've created a dynamic select field and can get their name with that. But I also need to grab their avatar as well.

9 years ago
6
Level 2

If i understand, you created some fields to save the ids of each co author of an article.

Is it right ?

Regards,
Mehdi

332 Posts
Kenneth
9 years ago
5
Level 3

Yes, correct. This is now just a dynamic select field which I want to repeat either with field x or group x depending on how I have to do it to get the avatar as well.

I'll give an examples. I'm "in-house" and am writing the article, but on the spot I've got a reporter who takes pictures and interviews people. I would then want to select this person from a list, and add them to the list of authors of the article. This is my goal.

9 years ago
4
Level 4

Hi,

ok, thanks.

There is two ways to do what you describe:

  1. to define an override of the position that contains the select dynamic field. With this solution, you will add your sql query in the PHP code of the override.
  2. to use the SQL field contained in the SQL package. In each field you will retrieve the path of each avatar starting from the id of a user. After you can apply the HTML typography plugin on a "free text" field to display the avatar itself with the tag "img".

Regards,
Mehdi

332 Posts
Kenneth
9 years ago
3
Level 5

Hi again, and thank you for the answer.

I've got questions:

Solution #1: do I use a query like the one described in the Joomla documentation, or does Seblod have a own way? I've found some in the old forum, but that dosn't work anymore.
(Joomla doc: https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase)


Solution #2: Can I have this field to use the value of a selection in a dynamic select field? The userid for the "assistant users" is not found in the created_by field in the database, that ID i get from the dynamic select field.

9 years ago
2
Level 6

Hi Kenneth,

  1. you can use this code
    $query = 'SELECT .... FROM ...';
    $result = JCckDatabase::loadresult( $query );
  2. the SQL package is available in the SEBLOD market. You can download it after you bye it by clicking in this link.

Regards,
Mehdi

332 Posts
Kenneth
9 years ago
0
Level 7

Thanks Mehdi, I'll test this and report back. Been quite busy, so haven't had the time to look into it yet.

251 Posts
Viktor Iwan
9 years ago
0
Level 7

Hey Mehdi.. do you have the manual and example for the SQL Pack: http://www.seblod.com/products/19162 ? thanks

9 years ago
0
Level 1

332 Posts
Kenneth
9 years ago
0
Level 1

Hi,

This is now solved.

I've got a dynamic select field repeated with field X to select several authors.

In my custom template I use this code to fetch the ID's of the other authors and to grab more another value from the database:

$test_coauthor = $cck->get('nyheter_fx_coauthors')->value;
$test_coauthor2 = $test_coauthor[0]->value;
if(!empty($test_coauthor2)) {
	foreach($cck->get('nyheter_fx_coauthors')->value as $gx) {
		$db = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->select('bruker_profilbilde');	
		$query->from($db->quoteName('#__cck_store_form_brukere'));
		$query->where($db->quoteName('id')." = ".$db->quote($gx->value));
		$db->setQuery($query);
		$result = $db->loadResult();
		echo '<img src="'.$result.'" class="img-circle img-responsive profilbilde">';
		echo '<p class="text-center">'.$gx->text.'</p>';
	}
}
<br>

This gives me their name (gx->text) and the id (gx->id) which I use in the query to feth the URL to the profile picture. Works like a charm.

You can see it in the article at http://drm24.no/nyheter/fargerik-folkefest-pa-fjell where two authors are selected.

Get a Book for SEBLOD