Solved: How do I get the value of the of the label and not the ID?

ahmedo

Member
I have an element which is a databasejoin. The dropdown shows the organization name but the value It stores is the ID. That is what I want. Please see screenshot. I can extract the id in my code with a line like this
$id = {fbk_listname___customer_name}; This may give me for example 15

However, what if I want to store the name of the customer instead of the id? I want to give me the name that belongs to that ID, example Intel Corporation (where its ID is 15).

https://www.awesomescreenshot.com/image/3209464/4d35540c53e8287b8a63f206d741a62d

Thanks.
 
Change the Value ...right now ID(recommended)...to organisation_name like the Label, it will then store the name in database instead of the id

That's what i do.
 
Change the Value ...right now ID(recommended)...to organisation_name like the Label, it will then store the name in database instead of the id

That's what i do.
Thanks for the answer. I can?t do that. I have too many records that have been saved already. I am almost sure there is away to pull that value.


Sent from my iPhone using Tapatalk
 
When you say "in my code", what code?

If you just need to get a field from the other table in your own code, given the ID, you can get whatever data you want by querying the database yourself.

Code:
$id = (int)'{fbk_listname___customer_name}';
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('name')->from('yourtable')->where('id = ' . $db->quote($id));
$db->setQuery();
$name = $db->loadResult();

-- hugh
 
As always Hugh, thanks a lot. I feel guilty when asking sometimes. One more question. :)

Can I do this
{customers__customerNameTemp} = $name;

Let me explain in details taking your example above
- I created an element call customerNameTemp in a list called customers. And then, wrote this.

Basically, want to assign the value of $name (as in your example above) to the new element name that I created for testing in the same list that the form is opening?
 
I finally got everything to work. I have no idea why I have to convert my fabrik list element to string when it is already a string. In any case, this is the code that worked. It has a been a great learning experience.
Basically, I have a form where we update customers who renew their subscription. Once the form is submitted, the new expiry date is also recorded in an another list where that matches their records.
Thanks everyone.

Code:
$customerId = {list1___customer_name};
$newExpiryDate = (string) '{list1___new_expiry_date}';

$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->update($db->quoteName('list2'))->set("current_expiry_date='$newExpiryDate'")->where("customer_name=$customerId");
$db->setQuery($query);
$db->execute();
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top