Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何根据选择更改数据库中显示的信息_Php - Fatal编程技术网

Php 如何根据选择更改数据库中显示的信息

Php 如何根据选择更改数据库中显示的信息,php,Php,我有许多数组的结构如下: ["data"]=> array(5) { [0]=> [2]=> array(3) { [0]=> string(45) "Account1" [1]=> string(9) "405105304" [2]=> string(4) "2712" } [3]=>

我有许多数组的结构如下:

["data"]=>
  array(5) {
    [0]=>
      [2]=>
      array(3) {
        [0]=>
        string(45) "Account1"
        [1]=>
        string(9) "405105304"
        [2]=>
        string(4) "2712"
      }
      [3]=>
      array(3) {
        [0]=>
        string(46) "Account2"
        [1]=>
        string(9) "410418784"
        [2]=>
        string(1) "0"
      }
正如您在我的示例中所看到的,我有两个帐户,每个帐户的数据如下:

 {
            $array = [];
            $path = $data->data[2]; //this is for Account1
            foreach($path as $key => $item){
                if($key > 1){ 
                    $array[] = [$item[8]];
                    $sum += $item[8];
                }
            }
            $avg = ($sum / count($array));
            return json_encode($array);
        }
正如你所看到的,我平均每8个值。问题是,我需要制作一个选择按钮,将此foreach应用于我选择的特定帐户

这就是我返回每个帐户名称的方式

      {
            $array = [];
            $path = $data->data[0];
            foreach($path as $key => $item){
                if($key > 1){ 
                    $array[] = [$item[0]];
                }
            }
            return json_encode($array);
        }
这就是我在select中回显帐户名称的方式

        <div style="margin: 5px 5px 0px; height: 30px; width: auto;">
            <div style="width: 100%; display: block;">
                <span style="display: none;">
                </span>
                <select style="width: 100%; border-radius: 5px;">
                    <option value="All" selected="selected" style=" width: auto;">All Campaigns</option>
                    <option value="405105304" style=" width: auto;"><?php echo \Helper::getCompanyNameForAdWordsAdCostPerConversion($data) ?></option>
                </select>
            </div>
        </div>

所有战役

我的问题是,我不知道如何根据所选帐户更改显示的数据。

首先,您必须在HTML中添加一个带有参数的链接,例如:

<a href="index.php?account=3">Account 2</a>

或者您可以将select放入表单中,使用$\u POST而不是$\u GET。

如果您不提交表单,则需要使用一些js/jquery/ajax
$path = $data->data[$_GET['account']];