Forums

calculation

GreyHead 05 Oct, 2011
Hi Kayrie,

I'm not sure that I completely understand what you want to happen here?

Are you saving the result to a database table? If so what is the structure of the table - do you have one record for each user, or one record for each application, or something else?

Bob
kayrie 05 Oct, 2011
i want to make one record to each user....

example..
user 1:
the max application is 15 times...
he applied one times....
it will become 14 right...
then the next time he applied...
the value wil start with 14...

yes,i want to save it to db table

.....
structure will lok like this...example

Total Apply:1
Total Balance:15
Current Balance:15-1 =14

....next time applied

Total Apply:1
Total Balance:14..
Current:14-1=13


.....
GreyHead 06 Oct, 2011
Hi Kayrie,

OK. You need to set up your table with a 'balance' column = 15

When the form load you read the table to see if they have any balance left; when the form is submitted you update the table to reduce the balance by 1. I'd do this with Custom Code actions in each place to run a simple MySQL query.

Bob
kayrie 06 Oct, 2011
As u see i already set up the Total Available to 15 here

<input value="15" id="L_status_id" name="L_totalavailable_id" type="hidden" />
<input value="" id="L_status_id" name="L_currentbalance_id" type="hidden" />



I want to make the value 'alive' with the balance for user is not static.....
if first time apply balance is 15....the second time will be less than 15,might be 13 or 12 because he/she has use the application....


Can u help me solve this... ;(
im not good enough in programming as this is my first project ....
GreyHead 06 Oct, 2011
Hi Kayrie,

I'm sorry but there just isn't enough time to run programming tutorials here. If you have a specific ChronoForms problem then we can try to help; but for general programming help you might get better answers from somewhere like Stackoverflow.

Bob
kayrie 07 Oct, 2011
This is mysql statement that i've been made...

DECLARE @RemainingLeave int

SELECT LeaveDaysApplied
       ,MaxLeaveDays
FROM <tablename> a

SET @RemainingLeave = MaxLeaveDays - LeaveDaysApplied

INSERT INTO <tablename> a
  (MaxLeaveDays)

VALUES(
@RemainingLeave)


how can i implement this in chronoform...
seems like i troubled u so much...
im sorry...juz asking
GreyHead 09 Oct, 2011
Hi Kayrie,

I'm not sure what the query is - it's got SQL syntax that I'm not familiar with.

I think it's trying to update the table. In Joomla! I'd use something like
<?php
// get this data from somewhere
$leave_days_applied = ???;
$user_id = ???;

$db =& JFactory::getDBO();
$query = "
    UPDATE `#__some_tablename`
        SET `RemainingLeave` = `RemainingLeave` - {$leave_days_applied}
        WHERE `user_id` = '{$user->id}' ;
";
$db->setQuery($query);
$db->query();

Bob
kayrie 10 Oct, 2011
em...many ways i tried already...
its been 2 weeks i've been working on this...
still no solution....

can u help me one last time ;(
by solving this....im using chronoform v3.2

i want to make one record to each user....

example..
user 1:
the max application is 15 times...
he applied one times....
it will become 14 right...
then the next time he applied...
the value wil start with 14...

yes,i want to save it to db table

.....
structure will lok like this...example

Total Apply:1
Total Balance:15
Current Balance:15-1 =14

....next time applied

Total Apply:1
Total Balance:14..
Current:14-1=13


.....


this is my form
<?php
$user = JFactory::getUser();
$Id = $user->id;
$Name = $user->name;
$Email = $user->email;
?>

<div class="form_item">
  <div class="form_element cf_heading">
    <h3 class="cf_text">Royal Application Form</h3>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Staff ID</label>
    <select class="cf_inputbox validate-selection" id="select_19" size="1" title=""  name="id">
    <option value="">Select here</option>
      <option value="<?php echo $Id ?>"><?php echo $Id ?></option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Name</label>
    <select class="cf_inputbox validate-selection" id="select_20" size="1" title=""  name="name_id">
    <option value="">Select here</option>
      <option value="<?php echo $Name ?>"><?php echo $Name ?></option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Email</label>
    <select class="cf_inputbox" id="select_21" size="1" title=""  name="email_id">
    <option value="">Select here</option>
      <option value="<?php echo $Email ?>"><?php echo $Email ?></option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;"Royal Type</label>
    <select class="cf_inputbox" id="select_5" size="1" title=""  name="L_royaltype_id">
    <option value="">Select Type</option>
      <option value="A.L">A.L</option>
<option value="M.L">M.L</option>
<option value="U.L">U.L</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Month</label>
    <select class="cf_inputbox" id="select_21" size="1" title=""  name="L_month_id">
    <option value="">Select Month</option>
      <option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_datetimepicker">
    <label class="cf_label" style="width: 150px;">From Date</label>
    <input class="cf_datetime" title="" size="20" id="L_datefrom_id" name="L_datefrom_id" type="text" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_datetimepicker">
    <label class="cf_label" style="width: 150px;">To Date</label>
    <input class="cf_datetime" title="" size="20" id="L_dateto_id" name="L_dateto_id" type="text" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Total Days Applied</label>
    <input class="cf_inputbox validate-number" maxlength="150" size="30" title="" id="text_9" name="L_totaldaysapplied_id" type="text" />
  


<input value="15" id="L_status_id" name="L_totalavailable_id" type="hidden" />
<input value="" id="L_status_id" name="L_currentbalance_id" type="hidden" />

  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Contact No.</label>
    <input class="cf_inputbox validate-number" maxlength="150" size="30" title="" id="text_11" name="L_contactno_id" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Reason(s)</label>
    <textarea class="cf_inputbox" rows="3" id="text_13" title="" cols="30" name="L_reason_id"></textarea>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textarea">
    <label class="cf_label" style="width: 150px;">Address</label>
    <textarea class="cf_inputbox" rows="3" id="text_16" title="" cols="30" name="L_address_id"></textarea>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_fileupload">
    <label class="cf_label" style="width: 150px;">Upload file(s)</label>
    <input class="cf_fileinput cf_inputbox" title="" size="20" id="file_17" name="L_upload_id" type="file" />
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_heading">
    <h4 class="cf_text">Project Manager Details</h4>
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Project Manager</label>
    <select class="cf_inputbox" id="select_19" size="1" title=""  name="L_pm_id">
    <option value="">Select PM</option>
      <option value="Hasyim Al-Habsi">Hasyim Al-Habsi</option>
<option value="Abu Abbas Al-Habsi">Abu Abbas Al-Habsi</option>
<option value="Mr. Ronald Richard">Mr. Ronald Richard</option>
<option value="Mr. Peter Stevens">Mr. Peter Stevens</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">PM email</label>
    <input class="cf_inputbox validate-email" maxlength="150" size="30" title="" id="text_20" name="L_pmemail_id" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<input value="Unapproved" id="L_status_id" name="L_status_id" type="hidden" />


<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_21" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


it seems like i've triied too much...
n getting morale down....
can anyone give me some hope by settling my probs....
if not then i can use dreamweaver and start all the way back... ;(
This topic is locked and no more replies can be posted.