1. 程式人生 > >近期處理多個Highcharts圖標時,碰到重復操作,所以編寫了一個流程控制器

近期處理多個Highcharts圖標時,碰到重復操作,所以編寫了一個流程控制器

null sql 控制 lin end created 格式 har 合並數組

HTML選擇頁面

技術分享圖片

第一部分:<?php

/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/8
* Time: 14:40
*/
include(‘common/common.php‘);
// 獲取初次加載必要信息
if(empty($_SESSION[‘firstYear‘]) || empty($_SESSION[‘firstMonth‘]) || empty($_SESSION[‘maxDay‘])) {
echo "<script>window.location.href=‘index.php‘</script>";
}
if(!empty($_GET[‘Pass‘])) {
$firstYear = $_SESSION[‘firstYear‘];
$firstMonth = $_SESSION[‘firstMonth‘];
$maxDay = $_SESSION[‘maxDay‘];

// 開始日期
$startDate = $firstYear."-".$firstMonth."-01";
// 結束日期
$endData = $firstYear."-".$firstMonth."-".$maxDay;
// 查詢該段日期內共有多少種織帶
/*
* 統計織帶類別
*/
$sel_ribbon_sql = "SELECT ID,ribbontype FROM ribbon";
$res = getRes($sel_ribbon_sql);

$ribbontype_List = array();
$numbers_List = array();
$new_ribbontype_List = array();
$new_numbers_List = array();

for($i=0;$i<count($res);$i++) {
$ribbontype_List[$i] = $res[$i][‘ribbontype‘];
$sel_sql = "SELECT SUM(numbers) as num FROM orders WHERE category = ".$res[$i][‘ID‘]." and state = 10 AND delivery >= ‘".$startDate."‘ AND delivery <= ‘".$endData."‘";
$sel_orders_num_List = getRes($sel_sql);
$numbers_List[$i] = $sel_orders_num_List[0][‘num‘];
}

$index = 0;
for($j=0;$j<count($ribbontype_List);$j++) {
if($numbers_List[$j] != 0) { // 如果某種織帶數量不為0
$new_ribbontype_List[$index] = $ribbontype_List[$j]; // 將不為0的織帶數量給index下標
$new_numbers_List[$index] = $numbers_List[$j]; // 名字給index下標
$index++;
}
}

$k=0;
while($k<count($new_ribbontype_List)) {
// 將數組轉換成higscharts可讀格式
if($res[$k][‘ID‘]==1) {
$arr1[] = array(
"name" => $new_ribbontype_List[$k],
"y" => intval($new_numbers_List[$k]),
"sliced" => true,
"selected" => true
);
} else {
$arr[] = array(
$new_ribbontype_List[$k],intval($new_numbers_List[$k])
);
}
$k++;
}
//合並數組
$arrs = array_merge($arr1,$arr);
$data = json_encode($arrs);
$_SESSION[‘data_num‘] = $data;

if ($_GET[‘Pass‘] == 1) {
echo "<script>window.location.href=‘chart_line_num.php‘</script>";
} else if($_GET[‘Pass‘] == 2) {
echo "<script>window.location.href=‘chart_columnar_num.php‘</script>";
} else if($_GET[‘Pass‘] == 3) {
echo "<script>window.location.href=‘chart_pie_num.php‘</script>";
}
} else {
echo "<script>window.location.href=‘index.php‘</script>";
}
第一部分進入分流(例舉其一):
  
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/4
* Time: 9:50
*/
include(‘common/common.php‘);
if(empty($_SESSION[‘data_num‘]) || "null" == $_SESSION[‘data_num‘]) {
        echo "<script>window.location.href=‘log_num.php?Pass=3;‘</script>";
} else {
$data = $_SESSION[‘data_num‘];;
}
include(‘tpl/chart_pie_num.html‘);

近期處理多個Highcharts圖標時,碰到重復操作,所以編寫了一個流程控制器