Show calc element value in database

kinkaz

Member
Hi,

I have a calc element with is calculated "on the fly" (calc on save: no).
I need to prefilter on that element.
My problem is that my element's field value is set to NULL (and not the the calc result) --> I can't pre-filter on "NULL" :)

Is there a way to "force" the calc element's value to be registered correctly and not to NULL in the database ?

Thanks

kinkaz
 
Calc values are always stored in the table on form submit, regardless of the "Only calc on save" setting. Setting this to "No" simply means that calcs are re-run when you display the element in (say) a list.

If your calc values are NULL in the table, then either those are rows which existed prior to adding the calc element, so have never been submitted with the calc running on them, so have no value. We don't automagically run the calc for existing data when you add / change a calc element.

Or, it means your calc is failing on submit, but working when displaying, for some reason.

If it's the latter, I'll need to see your calc code to get an idea as to why it might be failing on submit.

-- hugh
 
OK,

I understand the calc value is only refreshed in a list. Is there a way to make the pre-filter working on the list element data and not the database's one ?
 
kinkaz, but why you need this? It happened only during development, when you add new colums, so, it will fork fine in real life. If you really need to fill records - open and save each once, or make a script if database huge
 
I have an event's list. Users can register to them. The count element shows how many people are registered to every event. List is like this :

Event A - Date - Count
Event B - Date - Count
...

I want that if the count exceeds the value of 12 (which is the max capacity of the event), the event is no more displayed in the list.

My idea is to pre-filter : if this count element is LESS THAN OR EQUALS 12, the event is no more displayed in the list. But this not works as the element is set to "NULL" in the database.

Thanks

kinkaz
 
kinkaz, sorry, i am confused a little, are you using calculation element or count element?
In case of calc element it must work well.
Your table allows to add new records?
If yes, add new record, fill the form, and press Submit - you will see calculated data for THIS row, that stored in database.
If no - how you getting this table?
So, i mean, Fabrik never force to save records in list view mode, because it dosen't change without editing or adding new record. Tables are not coming from nowhere :)
 
I'm using a calculation element. I don't know why, but now the count is stored in the database. It's a 0 when I submit the (which is normal) in the database. But if I register to this event, the count shows '1' (as it should be) in the list but it's still '0' in the database !
 
open this table in the admin, to see record, edit and save the record (calc)!
If the code is correct, then there will be changes!
 
Thanks for your suggestions, it works ! But I need that to be done automatically. I don't want to go everyday on my website to edit and resave all of my forms...
 
Thanks Sergio, I'll take a look at it.

My code is :

$db =& JFactory::getDBO();
$config = JFactory::getConfig();
$value = '{odqeg_fab_cours___id}';
$query = "
SELECT COUNT(*)
FROM ".$db->nameQuote('odqeg_fab_inscriptions')."
WHERE ".$db->nameQuote('coursid')." = ".$db->quote($value).";
";
$db->setQuery($query);
$count = $db->loadResult();
$count = 12 - $count;
if ($count>0) {
$link = $config->getValue('live_site')."liste-cours/details/10/{odqeg_fab_cours___id}";
$texte = "<strong>S'INSCRIRE</strong><br />".$count." place(s) disponible(s)</a>";
return '<a href="'.$link.'">'.$texte.'</a>';
}
else {
return "<strong>COMPLET</strong>";
}
 
need to run this query in sql-mysql and get the result.

Your code is difficult for me!

I'm on my site using a simple code:

CREATE VIEW table_name
AS select id,Sum(score_sum)score FROM jk71f_Fabrik_score

It works great!
 
kinkaz, ok now i see.
Make all calculations when people register new events, not when showing results.
If needed, use handles when form saving data
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top