1. Fabrik 3.8.1 has been released. It is mostly bug fixes and feature enhancements, but does include two new plugins (push notifications, and the sequence element). As usual we strongly recommend testing the new release on a sandbox if your application is mission critical, and always do an Akeeba backup before updating.

differences (and average) between two fields

Discussion in 'Community' started by Gur, Jan 2, 2011.

Thread Status:
Not open for further replies.
  1. Gur

    Gur New Member

    Level: Community
    Hello!

    I'm newbee here and I want to use the fabrik to following:
    I give one number and one date(day and time) to system on every use of form.

    I need the following:
    - the differences between last date and the actually filled in hour (Y)
    - the differences between last number and the actually filled (X)
    - the X/Y

    Sample:
    1st: date and time: 2010.12.28, 21:34 number:9469,9
    2nd: date and time: 2010.12.29, 17:08 number:9475,2
    result: 0,27/hour (passed hours: 19,56)


    I have an idea: if I can defind the actual row after the data is filled (or saved) with id and the previuos with (id-1), I can make some operation with php code... Can it work? Plaase send me some tipps! ;D



    If the system will work, i will buy the bronse subsciption for other projects, but if not...

    Thanks for your help!
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    Yes, that's entirely possible, either with a calc element or a form submission script. Searching the forums for those two things should yield a lot of useful information.

    -- hugh
     
    1 person likes this.
  3. felixkat

    felixkat Senior Member

    Level: Community
    If it's any help the following code, (which I found on the forums), is what I used to work out somebody's age.

    I created a CALCULATION element called age.

    Within the calculation field I placed the following code.

    Code (Text):
    $date= '{Artist___artist_dob}';
    $date = strtotime($date);
    $now = time();
    $diff = $now - $date;
    $years = floor($diff / 31556926);
    return $years;

    The {Artist___artist_dob} part of the code at the beginning is retrieving the date from my Date of Birth element.

    The result will show the age of my artist.


    Obviously I'm working with ages here and you want hours and minutes but as Hugh says I imagine you'll find some code in the forums for what you want. Hopefully the above will help put it all together.
     
    1 person likes this.
  4. Gur

    Gur New Member

    Level: Community
    re

    Hello!

    Thanks for your help!
    It seems to be OK, but I didn't find information about the following: how can I use the previuos data for calculating? Because the first date and value are in the table when I want to calculate the different with the actually fileld.
     
  5. Gur

    Gur New Member

    Level: Community
    re

    Hello!

    But in my case the first date is in the table (the last filled date)...
    Can you send a suggestion how can I read that in form? May I need to use the element ID?
    Thanks for your help!
     
  6. felixkat

    felixkat Senior Member

    Level: Community
    Ahh okay, in that case you may want to do something in Javascript.

    So going with your original example you would have an element called 'passed hours'.

    Edit that element and on the TABS on the right you will see one called Javascript. Within there you should be able to perform a calculation on the '1st date & time' and '2nd date & time' fields.

    Or, have the Javascript run on the '2nd date & time' field so after you enter the details it will automatically update the 'passed hours' element, which you may want to make read only.


    You'll probably find JS exmaples on the forums but if not I imagine there to be loads out there on the WWW.
     
    1 person likes this.
  7. troester

    troester Well-Known Member Staff Member

    Level: Standard
    In the calcutaion element you can get the table data with
    PHP:
     $db =& JFactory::getDBO();
    $query = "SELECT whatever.....";
    $db->setQuery($query);
    $x= $db->loadResult();
    ....
     
     
    1 person likes this.
  8. Gur

    Gur New Member

    Level: Community
    Good evening everybody! (It's 11 PM in Hungary... :) )

    It seems to be great! I make a test and I share the results!
     
  9. Gur

    Gur New Member

    Level: Community
    Hello!

    I'm very tired...and I'm very looser...but I can't find the mentioned calculation element. (which window, etc...)

    I'm newbee here...if you can send me the address of tutorial...or an picture...or some word... :)

    Thanks for everybody!
    Good night!
     
  10. crawforw

    crawforw Member

    Level: Community
    The calculation element is available under the Downloads section of the fabrikar.com website to subscribers. You'll need to install it using Fabrik plugins and then it will show up in your element types when you add a new element. Then the field will be there.
     
  11. Gur

    Gur New Member

    Level: Community
    Hello!

    But as you see on the topic start, we find a sollution for this problem without buying the calculation. :)

    Have you got any other idea? ;D
     
  12. felixkat

    felixkat Senior Member

    Level: Community
    Well from my impression you wanted to do this realtime which is why I suggested the Javascript. Did you try this?
     
  13. crawforw

    crawforw Member

    Level: Community
    Sorry, I was skimming until about midway. Bad habit...good luck with the javascript.
     
  14. Gur

    Gur New Member

    Level: Community
    Hello my friend!

    I have a problem with the javascript. I Don't know, how can I reach the rows in the database with JS. ( the date different = date in last row - actual filled date)
     
  15. felixkat

    felixkat Senior Member

    Level: Community
    I think with all the replies I'm actually confused what you are doing now.


    Do you need the results realtime? Example, do you need to see the calculations before saving the form?

    Are you referencing rows from the database or from the form?
     
  16. Gur

    Gur New Member

    Level: Community
    I'm affraid this... :) It is my fault, because my english is very poor. :mad:

    Well, the process is the following:
    the user log in to the system. Filling the form with the following data's:
    1: date and time (sample: 2010.12.28, 21:34)
    2: number (9469,9)
    Press the "save" button.
    The system save the data to the database and give the answer:
    - the passed hours from last filled data
    - differences between the numbers.

    (The last filled date, time and number is in the sql database.)

    It is clear? :)
     
  17. felixkat

    felixkat Senior Member

    Level: Community
    Okay, yes that's a lot clearer. I thought the two times were entered in the same form at the same time, I now understand.

    It sounds like the calculation element is more suitable using the example that troester was suggesting, however you would need a subscription.

    I imagine it could be done in Javascript as well but I couldn't tell you how you would write it.

    Is each record a new time? So when you enter a time it looks at the last record to see the start time? Unless start & end time are two different elements, how does it know if it's a start time or end time or does it not matter.

    You did mention on your first post that you would subscribe if Fabrik can do what you need to do. If you subscribed you would get your solution via the calc element and would get faster support on the issue.
     
  18. gdevries10

    gdevries10 New Member

    Level: Community
    And I am also sure that this can be done whit the calc element, since it uses PHP, and as far as my knowledge goes PHP is a server side script (instead off javascript) so you can run sql queries whit it in this way:

    Code (Text):
    $db =& JFactory::getDBO();
    $db->setQuery("SELECT `fieldA` FROM `tablename` where `fieldC` = 'value'");
    $fieldA = $db->LoadResult();
    after the setQuery you can set every query you want, even select another database and so on.

    Since javascript is not a server side script it´s almost impossible (as far as my knowledge goes) to run sql queries on it

    Good luck whit Fabrik and indead what Felix said if you subscribe that brings you a lot off advantages (and I must say I found the pricing quit ok from what you get for it!)

    Greatings,

    Geert de Vries
     
  19. Gur

    Gur New Member

    Level: Community
    Maybe this is the best sollution, but where can I find detailed information about the calculation modul? ( And where can I find a detailed information or catalogue about the chart-drawing?)
    Good night!
     
  20. yudayuda

    yudayuda New Member

    Level: Community
    If you buy the bronze, you'll also get a details PDF user manual - it has info about the calc element. Plus the forums almost always have answers that at least will guide you in the right direction - just need to do a lot of searching sometimes...

    Do you mean Visualization? again - the use manual has good info.

    Lastly - the wiki for fabric2 is also full of knowledge.

    Good luck!
     
Thread Status:
Not open for further replies.

Share This Page