Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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循环的postgresql帮助_Php_Postgresql - Fatal编程技术网

关于php循环的postgresql帮助

关于php循环的postgresql帮助,php,postgresql,Php,Postgresql,我一直收到一个通知:未定义索引:这个查询有错误,我不明白为什么。。。我更习惯mysql,所以,也许语法是错误的 这是php查询代码: function get_demos() { global $session; $demo = array(); $result = pg_query("SELECT DISTINCT(did,vid,iid,value) FROM dv"); if(pg_num_rows($result) >

我一直收到一个通知:未定义索引:这个查询有错误,我不明白为什么。。。我更习惯mysql,所以,也许语法是错误的

这是php查询代码:

function get_demos() {
        global $session;
        $demo = array();
        $result = pg_query("SELECT DISTINCT(did,vid,iid,value) FROM dv");
        if(pg_num_rows($result) > 0) {
            while($r = pg_fetch_array($result)) {
                switch($r['did']) {
                    case 1:
                        $demo['a'][$r['vid']] = $r['value'];
                        break;
                    case 2:
                        $demo['b'][$r['vid']] = $r['value'];
                        break;
                    case 3:
                        $demo['c'][$r['vid']] = $r['value'];
                        break;
                }
            }
        } else {
            $session->session_setMessage(2);
        }

        return $demo;
    }
当我在pg提示符下运行该查询时,会得到以下结果:

"(1,1,1,"A")"
"(1,2,2,"B")"
"(1,3,3,"C")"
"(1,4,4,"D")"
"(1,5,5,"E")"
"(1,6,6,"F")"
"(1,7,7,"G")"
"(1,8,8,"H")"
"(1,9,9,"I")"
"(1,10,A,"J")"
"(1,11,B,"K")"
"(1,12,C,"L")"
"(1,13,D,"M")"
"(2,14,1,"A")"
"(2,15,2,"B")"
"(2,16,0,"C")"
"(3,17,1,"A")"
"(3,18,2,"B")"
"(3,19,3,"C")"
"(3,20,4,"D")"
"(3,21,5,"E")"
"(3,22,6,"F")"
"(3,23,7,"G")"

如果您想在$r中获得关联数组,则必须使用函数。

如果您想在$r中获得关联数组,则必须使用函数。

在while循环中尝试使用var_dump$r。事实上,找出不同的是它不喜欢的…然后请写下您自己问题的答案,并在48后接受它?在你的while循环中尝试一个var_dump$r实际上,发现它不喜欢与众不同的东西…然后请写一个你自己问题的答案,在48小时后接受它?hourspg_fetch_数组默认返回数值和关联索引,请参阅pg_fetch_数组默认返回数值和关联索引,请参阅