Second PHP variable doesn't work

Share RGraph:   To help my Google visibility (it can't get much worse!), if you like and use RGraph I'd appreciate it if you could link to me

« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by gooddmood on 17th October 2012
hi !
i have this
  var scatter = new RGraph.Scatter('cvs', [
                                               
                                                  [age,weight, '#CE2118'],
                                                  [weight,2, 'black'],
                                                  [24,2, 'black'],
                                                  [5,111, 'gray'],
                                                  [5,112, 'red'],
                                                  [12,114, 'gray'],
                                                  [0,110, 'black']
                                                 ]);
where to set data .
and instead of numbers i have done variables which are numbers.

so i define those variabls like that

var age = '<?php echo $_SESSION['age'];?>';
         var weight = '<?php echo $_SESSION['weight'];?>';

so the probleme is >
the if i make the variable in the first place it works but if i set the variable in second place it doesnt work.
forexemple in my data > the first data : the age work but not the weight
                       > the second data: the weight work

how to fix this please thanks so much for your help and your time.
Posted by RGraph Support on 18th October 2012
Hi there,

var age = '<?php echo $_SESSION['age'];?>';
var weight = '<?php echo $_SESSION['weight'];?>';

You problem may be these two lines. You've used single quotes - which makes the variables strings - regardless of what text they contain. In turn these strings are converted to numbers which will result in zeros. Try this instead:

var age = <?php echo intval($_SESSION['age']);?>;
var weight = <?php echo intval($_SESSION['weight']);?>;

(note the lack of single quotes).

Add a reply




« Back to message list