Problem with Element Dropdown, same values different labels

marioms

Member
Hello there!

I am having trouble making this work. So I have a billing system that calculates a total amount of money based on this:

f29b48ebcd4dce117cee8dd852ec6144.png


And a few of the contractors have the same rate per hour:

791046eed6990bf641a0177438854048.png


This is how it is being displayed on the form:

6bb82a4fdc2a045e113a6064378aa183.png


And once I submit, I can see the newly created entry on the list but the contractor is wrong, it just selects a random contractor with the same value:

9c737ca7dad3d84db80524dc2c1483ce.png


Is there a way to make it show the correct contractor? (i.e the one I selected on the form, even if they have the same values?) if not, what kind of solution I can apply?

Also, when I am back to the form for edit, it shows a totally different contractor again (but one with the same value as the selected one). So I am not sure how to fix this issue.

Thank you in advance!
 
You can't have the same value for different labels. The value is stored in the DB, how should anybody know which of the different labels belongs to it?
You can use an additional table/list with e.g.
id, rate, contractor
and a databasejoin element pointing to this table (with value=id[recommended]).

You can then fetch the rate from the database.
 
You've got the "value" concept totally wrong. If you use dropdown element, "value" should be unique like "contractor_name" or numeric like 1, 2, 3 etc.

And even better to use @troester's suggestion to have a separate list and dbjoin element for contractors.
 
You can't have the same value for different labels. The value is stored in the DB, how should anybody know which of the different labels belongs to it?
You can use an additional table/list with e.g.
id, rate, contractor
and a databasejoin element pointing to this table (with value=id[recommended]).

You can then fetch the rate from the database.

Thank you so much, that makes sense, I will make the additional table and the databasejoin element :)
 
You've got the "value" concept totally wrong. If you use dropdown element, "value" should be unique like "contractor_name" or numeric like 1, 2, 3 etc.

And even better to use @troester's suggestion to have a separate list and dbjoin element for contractors.

You are right, I totally got it wrong, I guess a need a coffee because my brain is not working properly this morning :p
 
Good morning!

I'm back again. I have done the new table with the ID, Contractor name and rate:

ef2d7a7323b18406d35735f5cc4237e3.png


And I created the new databasejoin element:

8bb5404c8b53d2de68118c4935b20dfb.png

I also updated the formula I have for calculating the rate * hours:

c6e69d20f033b7d2902f03c8d8f49eb5.png


So it is obviously not working at the moment because the new element points at the id of the contractor (with the name as a label) and not at the rate to make the calculation:

e374e2c53a5b59654015f4eb4ed1bbc4.png

So I would like to know how to fetch the rate so the calculation works. Is that something I need to add to the databasejoin element itself? to the formula?

Thank you in advance.
 
In calc element you can get the hourly rate something like:
Code:
$contractor = '{j32db_scitech___Contractor_raw}';

$mydb = JFactory::getDBO();
$mydb->setQuery("SELECT rate FROM j32db_contractors WHERE id = ".$mydb->Quote($contractor));
$hourlyrate = $mydb->loadResult();
Make sure you change the "rate" in the query to your real rate element name if it's something different.
 
In calc element you can get the hourly rate something like:
Code:
$contractor = '{j32db_scitech___Contractor_raw}';

$mydb = JFactory::getDBO();
$mydb->setQuery("SELECT rate FROM j32db_contractors WHERE id = ".$mydb->Quote($contractor));
$hourlyrate = $mydb->loadResult();
Make sure you change the "rate" in the query to your real rate element name if it's something different.


Thank you so much Juuser, it works fine! :)
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top