Forums

How to share variables between header, body and footer

toto72 19 Nov, 2009
Hello everybody, i'm new to chrono so my question i simple for the most of you (i hope).
I wanto to share tha value of a variable between header, body and footer. For example, i have a variable used in the body to count the records and i want to print the value in the footer. It seems that in the footer the varibale is not valorized. Why? How and where have i declare my vars to share its.

Thanks to anyone who can help me.
Salvatore
GreyHead 19 Nov, 2009
Hi Salvatore,

Please show us the code snippets for the counter in the body and footer.

Bob
toto72 19 Nov, 2009
something like this in the body (in $MyRow->money there are numbers):
<?php
$tmp = $MyRow->money;
$money_total = $money_total + $tmp;
?>


and in the footer:
<?php
echo $money_total;
?>

and the output is... empty!

Thanks at advance
Salvatore
GreyHead 19 Nov, 2009
Hi tot72,

Try adding global $money_total; in both places (and possibly in the header too??)

Bob
toto72 20 Nov, 2009
Hi GreyHead, thank you for your response. I solved inserting the global declaration in bot body and footer, it seems to be non necessary in the header. Just to give some ideas to anyone, i have inserted a div into the header, and via javascript into the footer i update the text of the div via innerHTML, with the value of the variable defined into the body.

Thanks again,
Salvatore
coffeej 29 Nov, 2009
I have a similar need in CC, but would prefer to avoid the javascript work around described in related posts.
I am writing a php if/then to display a link to "new record" in the footer only if a current record does not exist.
If a record does exist - the edit/delete links will be displayed in the body and the footer will not show.
The "global" idea sounded promising but kicked out lots of errors. Can you give me an example of syntax to set the variable and call it up in the footer?

I tried using this in the body to set the variable:

<?php 
global $hasvalue = $MyRow->cf_id;
?>

I tried using this in the footer to call it up:

<?php 
echo $hasvalue;
?>


Thanks in advance.
GreyHead 06 Dec, 2009
Hi coffeej,

There is another thread from a few months back where Emmanuel and I both posted slightly different ways of show a message when no record is found. You should be able to adapt this to meet your need. (No Javascript required.)

Bob
This topic is locked and no more replies can be posted.