• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Use data from query in field

chris92

New Member
Hi,

Before load form I use a php to make a query...

...
$formateur = $myDb->loadObject();
return $formateur;

and I just want to use the value, for example, username in an element like

return $formateur->username;

I try also:

$f = 'user_pro___username';
return $f;

Thanks
Chris
 
Last edited:
So what is the actual problem? I assume you have this in calc element or ...?

And how does your full code look like?
 
Thanks for your reply juuser,

in the form
$myDb = JFactory::getDbo();
$user = JFactory::getUser();
$id= $user->id;
$myQuery = $myDb->getQuery(true)
->select('*')
->from($myDb->quoteName('user_pro'))
->where($myDb->quoteName('user_id') . ' = ' . $id);
$myDb->setQuery($myQuery);
$formateur = $myDb->loadObject();

return $formateur;

in element:

return $formateur->username;

username is a column in the table user_pro (no prefix)
 
I'm assuming
- the field user_id in table user_pro is identical with the field id in the Joomla #__users table,
- but for some reason the "username" is not,
- you cannot or do not want to join your "main" list (which your form relates to) with a list based on the user_pro table,
- and you only need to have the the logged-in user's username from user_pro.

Then you don't need any "form PHP", but you should be good with simply using this in your (calc) element:
Code:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true)
    ->select($myDb->quoteName('username'))
    ->from($myDb->quoteName('user_pro'))
    ->where($myDb->quoteName('user_id') . ' = \'{$my->id}\'');
$myDb->setQuery($myQuery);
return $myDb->loadResult();

http://fabrikar.com/forums/index.php?wiki/placeholders/
 
Last edited:
Yes I understant for 1 field but I would want to make only one query before the form load.
And use the object with all the columns in each field.
do you understand, lousyfool?
thanks a lot for your help.
 
Last edited:
Actually I'm not 100% sure I get your setup and actual goal, but like @lousyfool said, you should just have this code in calc element and not in form plugins. Didn't make any syntax test, but your code seems fine with a quick look. If you need only username, then lousyfools snippet above seems even more optimal.
 
I have several fields to populate from the query.

I'm affraid by that but in pure php. You can use only one query to load all data from the db. And you can use it in a list or a form by a simple call like $obj->field1, $obj->field2...etc...

In your sample, I have to make one query by field. It is not very optimized.

Do you understand?

best regards
 
If you set "Only calc on save" to "Yes" in calc element settings, the query is only run once when you save a particular record. So no performance issues there. Please note that if you had previously "Only calc on save" set to "No" (that means calculating on the fly), you should open and resave each record to get the field value written to database. If you have a lot of records, it's obviously more efficient to make the "one time update" of the fields in PhpMyAdmin or similar.
 
We deviate completely from the subject. Please read my messages. It's easier than that. And sorry for my english
 
Unsatisfying answers usually start from a poorly modified questions or description of the current situation -> goal. I'm lost here about what you really want to achieve. "Have one optimal query somewhere" is not a clear description (at least not for me).
 
Sorry I know you do the best for me and a very big thank for that. I'm not very clear in my ask...
Best regards
Chris
 
Yes I understant for 1 field but I would want to make only one query before the form load.
And use the object with all the columns in each field.
This is not the way Fabrik is working.
Usually you have a Fabrik list linked to a database table, each element is linked to one of the columns and Fabrik is doing the query.
So I think we don't understand what you want/need to do at all.

Surely you can bypass/extend Fabrik's standards with php plugins, custom templates, calc elements etc but first you should know how the Fabrik basics are working.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top