title: postgresql help with php loop
body: <p>I keep getting an "Notice: Undefined index: did" error with this query, and I'm not understanding why...  I'm much more used to mysql, so, maybe the syntax is wrong?</p>
  
  <p>This is the php query code:</p>
  
  <pre><code>function get_demos() {
          global $session;
          $demo = array();
          $result = pg_query("SELECT DISTINCT(did,vid,iid,value) FROM dv");
          if(pg_num_rows($result) &gt; 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-&gt;session_setMessage(2);
          }
  
          return $demo;
      }
  </code></pre>
  
  <p>When I run that query at the pg prompt, I get results:</p>
  
  <pre><code>"(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")"
  </code></pre>