I'd like to show the sum of a field in the header of my form. Could you help me with the syntax of php?
Forums
How to show sum of a field on form
Hi pokomon,
I'm sorry but I don't understand your question. Please give us some more detail about exactly what you need to do.
Bob
I'm sorry but I don't understand your question. Please give us some more detail about exactly what you need to do.
Bob
In the header of my chronoforms-form I would like to show something like 'there are allready 30 of 60 seats reserved'. Where 30 is the sum of all reserved seats and seats is a field of my form and database. 60 is the maximum of seats but is not important, this is just text.
What is the syntax for showing 'there are allready' sum(seats) 'of 60 seats reserved'?
What is the syntax for showing 'there are allready' sum(seats) 'of 60 seats reserved'?
Hi pokomon,
In the form On Load action add a database query to get the number of bookings. You could use a DB Read action but Custom Code is probably as easy. Something like this
Bob
In the form On Load action add a database query to get the number of bookings. You could use a DB Read action but Custom Code is probably as easy. Something like this
<?php
$db = \JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__some_table` ;
";
$db->setQuery($query);
$form->data['bookings'] = $db->loadResult();
?>
Then add {bookings} in a Custom Code element in the Designer tab<p>there are already {bookings} of 60 seats reserved.</p>
Bob
Great! I would like to do this also in the chronoconnectivitypage. Is that possible?
Hi pokomon,
Yes I think so - you could add similar code to the Header box of the listing.
Bob
Yes I think so - you could add similar code to the Header box of the listing.
Bob
Hello!
I would add more información and to the same SQL with a "WHERE" user_id=logged user id.
For example:
But of course it didnt work... could you help me?
Thanks.
But of
I would add more información and to the same SQL with a "WHERE" user_id=logged user id.
For example:
<?php
$user =& JFactory::getUser();
$form->data['ActualUserID'] = $user->id;
$db = \JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `jos_kunena_user_topics` WHERE user_id={ActualUserID} ;
";
$db->setQuery($query);
$form->data['KunenaTemas'] = $db->loadResult();
?>
But of course it didnt work... could you help me?
Thanks.
But of
This topic is locked and no more replies can be posted.