Calculated Field II for today... What I wrong?

Discussion in 'Professional Support' started by paolo.tateo, Aug 26, 2009.

Thread Status:
Not open for further replies.
  1. paolo.tateo Member

    Level: Community
    $indirizzo = ({suss_primoascolto___residenzaindirizzo}," ",{suss_primoascolto___residenzacivico});
    return $indirizzo;

    Thanks
    Paolo

    PS: All in the same table
  2. cheesegrits Support Gopher

    Level: Community
    PHP:
    return  "{suss_primoascolto___residenzaindirizzo},{suss_primoascolto___residenzacivico}";
     
    Remember that we do the placeholder substitution before we evaluate your PHP fragment. And that all strings in PHP have to be quoted. So if you want to treat whatever gets substituted as a string, you have to wrap it in quotes.

    -- hugh
    1 person likes this.
  3. paolo.tateo Member

    Level: Community
    Many thanks,
    I managed to do what I wanted, but I still have some problems:
    (1) I have appended the full address of a person, but the calculated field size not permit to view this (see image)
    (2) The result of calculation is shown on screen, but is not stored on database
    (3) To get my results I used many fields (hidden) to go to recover information from another table, and then the field where I chained the whole.
    I could do everything with just one field?

    My table is suss_primoascolto

    I have calcolate for example the field residenzaindirizzo ({suss_primoascolto___residenzaindirizzo}) whit this code:

    $db = JFactory::getDBO();
    $db->setQuery("select residenzaindirizzo from suss_contatti where fabrik_internal_id = {suss_primoascolto___cartella_raw}");
    return $db->loadResult();

    I have calcolate the field residenzacivico ({suss_primoascolto___residenzacivico}):
    $db = JFactory::getDBO();
    $db->setQuery("select residenzaindirizzo from suss_contatti where fabrik_internal_id = {suss_primoascolto___cartella_raw}");
    return $db->loadResult();

    ....


    Concatenated field ({suss_primoascolto___residenzacalcolata}) was calculated as follows:

    return "{suss_primoascolto___residenzaindirizzo}, {suss_primoascolto___residenzacivico} {suss_primoascolto___residenzaindirizzo2} {suss_primoascolto___residenzacap} {suss_primoascolto___residenzacomune} ({suss_primoascolto___residenzaprovincia})";

    (4) The third problem concerns the fact that the pdf that is generated also displays the hidden fields. But on this subject I will open another thread.

    Attached Files:

  4. rob Administrator

    Level: Community
    Ive added a width option to the calculation element
    I cant replicate that one, what setting do you have for 'Only Calc on Save '?

    I guess so, if you only need to record one thing then one calc field would be enough
  5. cheesegrits Support Gopher

    Level: Community
    The 'calc' element should ALWAYS store in the table when you save the form, regardless of 'calc on save only'. The difference is whether we then re-calc when displaying on a table, or use the stored value. This can obviously have a significant effect on performance ... if set to "no" and the calc involves a db lookup ... and you render a table with 100 rows showing ... that's 100 extra queries on that page load.

    NOTE - I think there may be issues with using calc element values as placeholders within another calc ... someone else ran into that issue ... but as it's kind of a corner case, I'm punting that one till after 2.0 stable is out.

    So for now, if you can calculate everything in one go, in a single calc element ... you should do so. And wherever possible, set "calc on save only" to Yes.

    -- hugh
  6. cheesegrits Support Gopher

    Level: Community
    Just FYI, the reason I'm punting it is it ain't trivial, and may not even be fixable. It's a chicken and egg. Calc's aren't run until the 'store database' phase, in storeDatabaseFormat() ... which are obviously run in series, one after the other ... so if element A relies on a calc from element B, but element B hasn't been run thru storeDatabaseFormat() yet ...

    -- hugh
  7. paolo.tateo Member

    Level: Community
    What code can I use to do the calculation with only one field?
    I know how you should do logically (calculation variables and then the chains) but I do not know the syntax. Thanks
  8. peamak Moderator

    Level: Community
    Hi paolo,

    you should be able to do in one field what you do in many... what table/group/element are we talking about, if you want me to look at it quickly?
  9. paolo.tateo Member

    Level: Community
    Hi peamak!

    You can watch the beginning of this thread: contains the information you need, or you need more?

    Thanks
  10. peamak Moderator

    Level: Community
    I think it's ok now! :D

    I called the calc I used 'calc_residenza' and I unpublished the calc you made. Tell me if everything is alright or if you have any question!
  11. cheesegrits Support Gopher

    Level: Community
    Just for completeness, can you paste the code you used here?

    -- hugh
  12. peamak Moderator

    Level: Community
    Oops, sorry I forgot to do that:

    PHP:

    $db = JFactory::getDBO();
    $db->setQuery("select residenzaindirizzo, residenzacivico, residenzaindirizzo2, residenzacap, residenzacomunetxt, residenzaprovinciatxt from suss_contatti where fabrik_internal_id = {suss_primoascolto___cartella_raw}");
    $concat = $db->loadObject();
    $residenza = $concat->residenzaindirizzo;
    $residenza .= ', '.$concat->residenzacivico;
    $residenza .= ' '.$concat->residenzaindirizzo2;
    $residenza .= ' '.$concat->residenzacap;
    $residenza .= ' '.$concat->residenzacomunetxt;
    $residenza .= ' '.$concat->residenzaprovinciatxt;
    return $residenza;
     
    Which, now that I see again, could be simplified a little.

    PHP:

    $db = JFactory::getDBO();
    $db->setQuery("select residenzaindirizzo, residenzacivico, residenzaindirizzo2, residenzacap, residenzacomunetxt, residenzaprovinciatxt from suss_contatti where fabrik_internal_id = {suss_primoascolto___cartella_raw}");
    $residenza = $db->loadObject();
    return $residenza->residenzaindirizzo.', '.$residenza->residenzacivico.' '.$residenza->residenzaindirizzo2.' '.$residenza->residenzacap.' '.$residenza->residenzacomunetxt.' '.$residenza->residenzaprovinciatxt;
     
    1 person likes this.
  13. paolo.tateo Member

    Level: Community
    Very well, many thanks !

    Paolo
Thread Status:
Not open for further replies.

Share This Page