【问题标题】:PHP : How to set array Value with $_GETPHP:如何使用 $_GET 设置数组值
【发布时间】:2015-06-02 18:23:18
【问题描述】:

我尝试将 $_GET[] 的值设置为数组对象

这是我的代码

$X=array(
'status_1'=>'"'.$_GET['hasil_1'].'"',
'status_2'=>'"'.$_GET['hasil_2'].'"',
'status_3'=>'"'.$_GET['hasil_3'].'"',
.
.
'status_17'=>'"'.$_GET['hasil_17'].'"');

//Faktor Klasifikasi
$n = 'derajat';

//nama tabel
$table='tabel';

classify($X,$n,$table);

它不工作。

这是网址

http://localhost:8080/tugas/sispak/hasil.php?hasil_1=1&hasil_2=1&hasil_3=1&hasil_4=1&hasil_5=1&hasil_6=0&hasil_7=1&hasil_8=1&hasil_9=0&hasil_10=1&hasil_11=1&hasil_12=1&hasil_13=1&hasil_14=1&hasil_15=1&hasil_16=1&hasil_17=1

但是,如果我像手动编写它

$Y=array(
'status_1'=>'1',
'status_2'=>'1',
'status_3'=>'1',

.
.
'status_17'=>'1'
);

有效!!

这是我处理数组值的地方

//var_dump($allclass);
    foreach($allclass as $c=>$p)
    {
        foreach($X as $x=>$y)
        {
            $i = mysql_query("select count(*) as num from ".$table." where ".$n."='".$c."' AND ".$x."='".$y."'");
            $j = mysql_fetch_array($i,MYSQL_ASSOC);

            $P[$c][$x] = round($j["num"]/$allclass[$c],2);

    //Exception: P(data/class) might be 0 in some cases, ignore 0 for now
            if($P[$c][$x] != 0)
                $argmax[$c] *= $P[$c][$x];
        }
        $argmax[$c] *= $Pc[$c];
    }

请大家帮帮我

【问题讨论】:

  • 你在做'status_1' => '"foo"',带有额外的引号。
  • “它不起作用” 永远不要认为这是一个可以接受的问题描述。如果你刚刚打印出你的 MySQL 查询,你就会发现问题......

标签: php url get


【解决方案1】:

你不需要所有这些引号,尝试如下:

$X = array(
    'status_1'=> $_GET['hasil_1'],
    'status_2'=> $_GET['hasil_2'],
    'status_3'=> $_GET['hasil_3']
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 1970-01-01
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    相关资源
    最近更新 更多