Lord_Helmchen VIP
Total posts: 31
30 Jul 2020 18:23

How to get the value of a parent field? I have a books database. The author is a parent field and i need this value to make a search link. what i have is

echo '<a class="button button-block button-3" target="_blank" href="/ https://www.google.de/search?q= '.urlencode($record->title).'"><i class="fa fa-fw fa-google"></i> Google</a>';

but i need something like

echo '<a class="button button-block button-3" target="_blank" href="/ https://www.google.de/search?q= '.urlencode($record->title).urlencode($record->author).'"><i class="fa fa-fw fa-google"></i> Google</a>';

Last Modified: 01 Aug 2020


Sergey
Total posts: 13,748
31 Jul 2020 04:50
urlencode(JFactory::getUser($record->user_id)->get('username'))

Lord_Helmchen VIP
Total posts: 31
31 Jul 2020 14:05

Hello Sergey, thanks for your answers. But it is not what i needed. Sorry i was not clear enough. I don't need the author of the article. I have this

stdClass Object
(
[id] => 484
[title] => Das Original
[published] => 1
[access] => 1
...
[categories] => Array
(
[5] => Hörbücher
)
[fieldsdata] => Das Original
[fields] => {"11":{"image":"uploads\/image\/2017-08-24\/1503594684_bb4d0954920a12183371f143dd9c4c9b.jpg","realname":"Grisham_J_Das_Original_2MP3_179204.jpg","filename":"1503594684_bb4d0954920a12183371f143dd9c4c9b.jpg"},"12":"
\r\n
Inhalt....
Charles Brauer macht Das Original <\/i>zum H\u00f6r-Ereignis.<\/p>","13":[140],"15":[483],"14":"25","16":null,"20":["Thriller"],"18":"604","19":"2","17":"978-3-8371-4008-8","21":["2017-08-21 00:00:00"],"23":[0],"22":{"asin":"3837140083","mode":"lookup","category":"All"}}
[comments] => 0
..
)

So $records->title is "Das Original". I would need the value of the parent "15":[483]. It should be "John Grisham" in this example.


Lord_Helmchen VIP
Total posts: 31
01 Aug 2020 16:26

Hi Sergey, got it working. Here is my code.

$author_json = (json_decode($record->fields, true));
$author = ItemsStore::getRecord($author_json[15][0]);

echo '<h4>&#187;'.$record->title.'&#171; finden bei:</h4>';
echo '<a class="button button-block button-3" target="_blank" href="/ https://www.genialokal.de/Suche/?q= '.urlencode($record->title).'+'.urlencode($author->title).'"><i class="fa fa-fw fa-book"></i> genialokal.de</a>';

Live example here: https://www.eisradio.de/hoerbuchecke/hoerbuecher/item/5-hoerbuecher/478-labyrinth-elixier-des-todes

Powered by Cobalt