如果查询没有返回结果页面根本没有加载 - 使用来自ajax调用的Google图表

时间:2015-07-12 19:58:51

标签: codeigniter join

我的查询有问题。我必须显示一张桌子上的所有物品,这些物品都是针对一家公司的。无论哪个用户将数据库插入数据库,所有用户都必须只查看他们工作的公司的订单。

问题是,当用户公司的订单头没有订单时,它根本不会加载页面。怎么做这个查询? 我的疑问是:

$company = $this->session->userdata('logged_in')['company'];
$this->db->select('*');
$this->db->from('orderitems');
$this->db->join('ordersheader', 'ordersheader.idOrder=orderitems.idOrder');
$this->db->join('customer', 'ordersheader.idCustomer=customer.idCustomer','left');
$this->db->join('systemusers', 'systemusers.idSystemUsers=ordersheader.user_id');
$this->db->where('systemusers.company', $company)

编辑:我将通过谷歌图表显示我的完整代码和我的视图,我从ajax调用中获取数据。认为这就是问题所在。



  $(document).ready(function() {
   
    google.load("visualization", "1", {packages:["corechart"]});
                  
    $.ajax({
      type: 'get',
      url: "<?= base_url() ?>index.php/receivedOrders/column_chart/",
      dataType: "json",
      // cache: false,
      success: function(jsonData){

        drawChart(jsonData);

      }
    });              
      
 
  function drawChart(jsonData) {

    var data = new google.visualization.DataTable(jsonData);
    
    var options = {     
      hAxis: {
      title: '<?php echo lang("haxis_date"); ?>',
      format: 'h:mm a',
      },
      vAxis: {
        title: '<?php echo lang("chart_average_price"); ?>'
      },
      width:'400',
      height:'300',
      backgroundColor: 'none',
      colors:['#ec8f6e', '#e6693e', '#e0440c', '#f3b49f', '#f6c7b6'],
        legend: { position: 'top', maxLines: 3,alignment: 'center' },
      };
      var chart = new google.visualization.ColumnChart(document.getElementById('column_chart'));
      chart.draw(data, options);
    }
  });
&#13;
&#13;
&#13;

我为图表调用json数据的控制器方法是:

&#13;
&#13;
<?php 
public function column_chart() {   
        
      $size = $this->uri->segment(3);
      $interval = $this->uri->segment(4);
      $firms = $this->Receivedorders_model->average_price_by_week($size,$interval);
     
      $p = array();
      foreach ($firms as $key => $firm) {
        $p[$key] = array('c' => array(array(
          'v' =>  $firm['interval'],  
        ),
        
     
        array(
          'v' =>  round($firm['unitPrice'],2), 
        )));
      }
      echo json_encode(array(
      'cols' => array(
          array('id' => 'name',  'label' => lang("customer"),  'type' => 'string'),
          array('id' => 'incomes', 'label' => lang("chart_average_price"),  'type' => 'number'),

        ),
        'rows' => $p

      ));
      
    }
&#13;
&#13;
&#13;

0 个答案:

没有答案