doujia9204 2015-09-30 22:51
浏览 30
已采纳

Google图表中的PHP字符串连接

I am passing PHP session variables to a Google chart object. The following works fine:

      function drawChart() {

    var data = google.visualization.arrayToDataTable([
      ['Descriptor', 'Items checked/Total number of items', { role: 'annotation' }],
      ['Attention', <?php echo $_SESSION["A"];?>, <?php echo $_SESSION["A"];?>],
      ['Auditory', <?php echo $_SESSION["AUD"];?>, <?php echo $_SESSION["AUD"];?>]           
  ]);

Everything works fine when the $_SESSION["A"] variable is by itself, and will print an interger in the chart ie. 12. However, when I try to concatenate '/12' to the $_SESSION["A"] variable in hopes of echoing '12/12' in the chart, I end up getting '1' in the chart (it is doing the math on 12/12). Here is the faulty code:

      function drawChart() {

    var data = google.visualization.arrayToDataTable([
      ['Descriptor', 'Items checked/Total number of items', { role: 'annotation' }],
      ['Attention', <?php echo $_SESSION["A"];?>, <?php echo $_SESSION["A"]."/12";?>],
      ['Auditory', <?php echo $_SESSION["AUD"];?>, <?php echo $_SESSION["AUD"]."/12";?>]           
  ]);

How do I concatenate "/12" to an integer without it doing the math?

  • 写回答

1条回答 默认 最新

  • duan198811 2015-09-30 22:59
    关注

    put single quotes so that js does not make the math and treat the value as a string instead:

    ['Auditory', <?php echo $_SESSION["AUD"];?>, '<?php echo $_SESSION["AUD"]."/12";?>']           
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号