PHP Code create to radiobutton

Kant

Member
I want a php query for a radiabutton. Unfortunately, I only get the numerical value

Code:
$db = FabrikWorker::getDbo(false, 3);
$query = $db->getQuery(true);
$query->select('vorhanden')->from('benutzer_daten')->where('user_id = ' . JFactory::getUser()->get('id'));
$db->setQuery($query);
return $db->loadResult();


What can I change

regards
Oliver
 
Where do you use this code?
BTW:
Don't use $db, this may override a variable $db already used.
Use something like $mydb, $db3 ...
 
I had used the code in all queries. Had set the element form only read, but I have changed it now.
Despite this change, the values in the elements dbjoin despite the change? I can not find a setting only read.
Can I prevent that?

regards
Oliver
 
But where do you use the queries?
Element default? Form php plugin (running when)? A cron job? ...
Is "radiobutton" a radiobutton element or a dbjoin element displayed as radiobuttons?

What do you want to achieve?
 
Troester asked the question I was about to, which is whether this is actually a radio element, or a join set to radio.

Typically, if you need to "do stuff" with a radio or dropdown with your own queries, it should be a join element to another table, set to display as radio or dropdown, not a radio or dropdown element.

The reason being that it's not easy to get at the labels for a radio or dropdown element, because there are stored in Fabrik's internal metadata tables, and are not submitted with the form. That's not a Fabrik thing, it's an HTML form thing. Labels are not part of the form input, they are just "decoration", and don't get submitted with the data. It is possible to get the labels, but it involves loading the specific element model and calling additional functions.

Whereas if you use a join, you can then just extend your query to get the "label" from the other table.

-- hugh
 
Ok, I changed the element to a radio join. But I would need some help for the code.
First of all, I can not update the element by autfill, because I do not use a joomla db, so I have must to create a code.

There are two tables join benutzer 'id" to benutzer_daten 'benutzer_id'
Depending on the user, a data record should be read from benutzer_daten.

I read the id from list as follows:
Code:
$mydb = FabrikWorker::getDbo(false, 3);
$query = $mydb->getQuery(true);
$query->select('id')->from('benutzer')->where('user_id = ' . JFactory::getUser()->get('id'));
$mydb->setQuery($query);
return $mydb->loadResult();


I need a further query that should be in this way.

$query->selct('vorhanden')->from('benutzer_daten')->where('benutzer_id') = $mydb

How do I connect this query?

regards
Oliver
 
If I'm understand you correctly, you could do it in one query, joining the tables ...

Code:
$mydb = FabrikWorker::getDbo(false, 3);
$query = $mydb->getQuery(true);
$query->select('bd.vorhanden')
   ->from('benutzer_daten AS bd')
   ->leftJoin('benutzer as b ON b.beutzer_id n= bd.id')
   ->where('b.user_id = ' . JFactory::getUser()->get('id'));
$mydb->setQuery($query);
return $mydb->loadResult();

-- hugh
 
Not sure what you mean by "not the opposed", but I assume you mean "not the label".

Is benutzer_daten.vorhanden a join to another table? If so, you'd need to join that as well ...

Code:
$mydb = FabrikWorker::getDbo(false, 3);
$query = $mydb->getQuery(true);
$query->select('c.whatever_the_field_you_use_as_the_label_is')
   ->from('benutzer_daten AS bd')
   ->leftJoin('benutzer as b ON b.beutzer_id = bd.id')
   ->leftJoin('whatever_vorhanden_joins_to AS c ON c.id = bd.vorhanden
   ->where('b.user_id = ' . JFactory::getUser()->get('id'));
$mydb->setQuery($query);
return $mydb->loadResult();

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top