title: sql result in php matrix according sorted by branches/product/size
body: <p>I've been trying hard to figure out how to do matrix from the result of an sql query where the x is location, y is the size/description and the data filling are the quantities available in each location according to the size and color.</p>
  
  <p>I have it done using pl/sql but not php. I want to transform the forms to a web layout in order to access it from anywhere. 
  the query is:</p>
  
  <pre><code>    $q5="select  artdesc DECRIPTON ,  ARTUPRB PRICE$ ,depcode LOCATION,  ARDQTDIS
            QUANTITY from fgart a, fgartdep b where a.soccode='01' and artfam =:fam and 
      artdiv=:div  and artsec=:sec  and artsubsec =:subsec and 
           (EXISTS 
       (select distinct artserial from fgart   where soccode ='01' and artsec =:sec 
       and artsubsec =:subsec and artfoucode =:wartfoucode   and artserial = a.artserial)    
           or EXISTS 
      (select distinct artfoucode from fgart where    soccode ='01' and artsec =:sec and 
      artsubsec =:subsec and artfoucode = a.artfoucode and  artserial =:wserial))
      and 
      b.soccode ='01' and b.bracode ='01' and a.artcode = b.artcode 
       and   depcode  &lt;&gt; '99'
         AND ARDQTDIS &lt;&gt; '0' 
           order by artdesc";
  </code></pre>
  
  <p>I have a small query prior of this one where I catch all the variables and pass them to the above sql.<br>
  I have managed to do a normal listing using the below code:</p>
  
  <pre><code>    &lt;?php
      $r7=oci_parse($oconn,$q5);
      $r8 = oci_execute($r7);
      sleep(100); 
      if (oci_execute($r7)){ 
      usleep(100); 
      print "&lt;TABLE border \"1\" cellpadding=\"3%\"&gt;"; 
      $first = 0; 
      while ($row = @oci_fetch_assoc($r7)){ 
              if (!$first){ 
                      $first = 1; 
                      echo ("&lt;TR&gt; &lt;TH bgcolor=\"#FF9900\" &gt; &lt;font color=\"FFFFFF\"&gt;" ); 
                      echo( implode("&lt;/TH&gt;&lt;TH bgcolor=\"#FF9900\"&gt;", array_keys($row))); 
                      echo ("&lt;/TH&gt; &lt;/TR&gt; &lt;/font&gt; \n"); 
              } 
              echo ("&lt;TR&gt;&lt;TD bgcolor=\"#D0D0D0\" &gt;"); 
      echo (@implode("&lt;/TD&gt; &lt;TD bgcolor=\"#F0F0F0\"&gt;",str_replace ($Woutl,  Wdesc,
      array_values($row))));  
              echo ("&lt;/TD&gt; &lt;/TR&gt;\n"); 
      } 
      echo ("&lt;/TABLE&gt;"); 
      ?&gt;
  </code></pre>
  
  <p>Please if anyone can direct me the right track in order to get result similar to the below:</p>
  
  <pre><code>              location (x) :         dt    sk    abc    ss
      Item desc /size (y):
      blue  46                         2      1     0     4
      blue  48                         1      1     1     0   
      blue  50                         0      0     2     1    
      grey  44                         5      1     1     1
      grey  46                         4      1     1     1       
      grey  50                         3      2     2     0    
  </code></pre>