duanjiao4763 2013-10-08 16:09 采纳率: 0%
浏览 55
已采纳

PHP,谷歌图表到Joomla网站

I try to integrate Google Pie Chart to my Joomla 3.1 website in a bit of tricky way. The chart is going to take data from the database and show it on the front-end.

Instead of the standard way to put data

['Work', 11]

I put it this way

["<?php echo $params->get('label_1')?>", <?php echo $results1?>],

["<?php echo $params->get('label_2')?>", <?php echo $results2?>],

and everything is all right. PHP takes data from my administrator panel, where I put a value for label_1 and it takes result1 after making some calculations with data in the database. Everything works correctly.

The problem comes when for example I have no data in the database for $result2 to calculate while everything is ok with $result1. I made a switcher to hide or show specific parameters and made this code for it

<?php if ($this->item->params->get('cpn_1')):           
          echo '["' . $params->get('label_1') . $result1 . '],';
        endif;?>

but it does not work and I cannot find where the mistake is. This should check if I switched on or off the specific part of the chart to be displayed on the front-end. After I create the page from where the data should be taken from database I switch on the piece of the chart from my back-end and it should work.

I also consider there should be a better way to do all this. The problem is that this is going to be a module and in case some day some tables or columns from database will be empty the page will not load at all.

  • 写回答

1条回答 默认 最新

  • doutuohan6606 2013-10-09 07:44
    关注

    If it's a module it will definitely not be $this->item->params but just $params eg:

    <?php if ($params->get('cpn_1')):           
        echo '["' . $params->get('label_1') . '", ' . $result1 . '],';
    endif;?>
    

    Edit: Also you where missing quote-marks and a comma after label1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?