databasejoin and calc

aje

Member
Hi

Have been trying to get a calc field depending on a join element to work.

table1
colums: id, date, name, value1, value2, value3, value4

table 2
colums: id, date, name, price1, price2, price3

Form1 table2
tbl2_name - field element
choose from table1: databasejoin element (value: table1_id, label: table1_name)
tbl2_price1 * tbl1_value1 (calc element)
tbl2_price2 * tbl1_value2 (calc element)

Tried with:

$verdi = '{table1___hus_stand_verdi_raw}'; (my databasejoin element name)
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('value1')->from('table1')->where('id = ' . $db->quote('$verdi'));
$db->setQuery($query);
$price = $db->loadResult();

return $price;

Anyone see whats wrong ? I only get undefined

Is there a better way to load values into a form from another table ?
 
Got it to work with :) After much trying

$verdi = '{tabl1___hus_stand_verdi_raw}';
$db = JFactory::getDbo();
$query= "SELECT `table1`.`value1` FROM `table1` WHERE tbl1.id = '$verdi'";
$db->setQuery($query);
$price = $db->loadResult();
return $price;
 
you should use the db->quote() method for quoting variables, to avoid potential SQL injection attacks:

PHP:
$verdi = '{tabl1___hus_stand_verdi_raw}';
$db = JFactory::getDbo();
$query= "SELECT `table1`.`value1` FROM `table1` WHERE tbl1.id = " . $db->quote($verdi);
$db->setQuery($query);
$price = $db->loadResult();
return $price;
 
Thanks :) Will change them right away :) Got another problem. I have made a form with 5 inputs and one of them have a databasejoin drop-down. Have many calculation fields where i use a % from another table depending on whats in the databasejoin drop-down.
so the form looks like
cost ( field ) ----------- profit (calc field(cost/100 * % from another table depending on a db join drop down)) ---------- sales price (calc field(cost + profit))

Everything works great exept in edit form view. If i changes the % (in another table and another form) i need it to update the calculations in edit view in this form. If i change the dropdown to another value and back again it works. So i need a trigger to run the calculation again if the % have changed. Hope this can be done because i have used a 1 -2 weeks on the application.
 
Thanks, it works great. Now i see that the record wont update with my custom template. When i use it to add a new record it works but not when i try to update a record. If i try the bootstrap template it works.

I deleted the foreach loop (like you did in the viemo video) and added the fields like this:

$list1 = $this->groups['Prislister'];
$plnavn = $list1['pl_navn']->element;

php echo $plnavn

Between the code:
<div class="row-fluid nav">
<div class="span6 pull-right">
<?php
echo $this->loadTemplate('buttons');
?>
</div>
<div class="span6">
<?php
echo $this->loadTemplate('relateddata');
?>
</div>
</div>

And the

<?php
if ($model->editable) : ?>
<div class="fabrikHiddenFields">
<?php echo $this->hiddenFields; ?>
</div>
<?php
endif;

Is there more i need to add ?
 
In a form, all element's need to be wrapped witih a container div, so something like :

PHP:
<div class="control-group <?php echo $plnavn->containerClass; ?>" >
...
</div>
 
Hi
Cant get the edit for still to work, could you have taken a look at my file if i sent it to you ?
 
Now i have added the details on my sites. I had to setup the services and the website on a new server.
 
hi I logged in to the front end but don't see any menu link or text 'prislister' on the home page. Which URL is the list on?
I then tried logging into the admin to try to find the list but I get a 500 internal error when I try to log in with the admin account details you supplied, could you check those please?
 
hmm still getting the 500 error when I try to log in with my user. Did you check that it works?
 
Hi - I can log in, I'm not sure when you say 'it works' are you talking about my login or the page, because for me things seem to be working ok?

I go to index.php/kunderegister/form/10/6
and i see for example Ansvarlig prosjektering Bidrag = 7388
I then select a different 'Standard verdier' and the value update.
Finally if I re-select the initial Standard verdier value Ansvarlig prosjektering Bidrag is re-set to 7388

That being said there are a LOT of ajax requests being fired in this way which could cause issues with server time outs . It might be better to do this via a user ajax script which is fired once one when select list is changed, and then runs one query to get the data, and updates the fields with one callback. The docs for that feature are here: http://fabrikar.com/forums/index.php?wiki/user-ajax/
 
If i change the name, dropdown og choose save it wont save. I get message its updated but it doesnt. Another thing i dont get to work is the pdf. Have changed the format, and tried i simple list/form but i cant get it to work. Have tried updated with github but still doesnt work.
 
If i change the name, dropdown og choose save it wont save. I get message its updated but it doesnt
I'm not quiet sure what that has to do with my previous post?
Is this a different issue, if so it would be best to make one thread per question to make it clear to me which issue I am dealing with.
That being said, check that your list's advanced section allows for you to update the 'Alter field types' to 'yes' (or that its set to global and the corresponding global configuration option is set to yes)

For the pdf try getting the latest version of dompdf from their github repository https://github.com/dompdf/dompdf
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top