title: my sql fetch array
body: <p>i have a transaction database with the following fields</p>
  
  <pre><code>trans_id    prod_id
      1          1
      1          2
      1          3
      2          1
      2          3
  </code></pre>
  
  <p>i need this to be converted into array in which all the products belonging to same transaction will be in one array so i can do the processing for this im making use of the following code however it doesn't seem to work. I checked the the length of $value during iteration of the while loop it first shows 2 and then 2 again instead of 3 and 2
  the entire code is like this</p>
  
  <pre><code>&lt;?php
  
  // MySQL Database Structure:  
  // Name: tree
  // Table: node
  // Columns:id, parent, child
  
  
  $con=mysql_CONNECT("localhost","root","");
  if (!$con)
  {
      die('Could not connect: ' . mysql_error());
  }
   mysql_select_db("tree", $con);
  
   mysql_query("truncate table node");
  
   $sql="INSERT INTO node (data,parent) VALUES(0,0)"; //first insertion for the root node
   mysql_query($sql);
   $par1=mysql_query("SELECT id FROM node where data=0");
   $par=mysql_fetch_array($par1); 
   //echo $par['id'];
   $abc="";
   for($z=1;$z&lt;=3;$z++)
   {
      $result= mysql_query("SELECT prod_id FROM user_prod WHERE trans_id=".$z);
      while($value=mysql_fetch_array($result))
      {
          $abc.=$value['prod_id'].',';
      }
      $abc=substr($abc,0,-1);
      $par=1;
      $list=explode(',',$abc);
      echo $list;
      $size=count($list);
      echo $size;
      for($i=0;$i&lt;$size;i++)
      {
          $sql="SELECT * FROM node where parent=".$par;
          $result=mysql_query($sql);
          $num=mysql_num_rows($result);
          if($num==0)
          {
              $x="INSERT INTO node (data,parent) VALUES ($list[$i],$par)";//new value at root
              mysql_query($x);
              $par1= mysql_query("SELECT id FROM node where data=$list[$i]");
              $par=mysql_fetch_array($par1);
          }
          else
          {
              while($x=mysql_fetch_array($result))
              {
                  if($x['data']==$list[$i])
                  {
                      $par1= mysql_query("SELECT id FROM node where data=$list[$i]");
                      $par=mysql_fetch_array($par1);
                      break;
                  }
                  else
                  {
                      $x="INSERT INTO node (data,parent) VALUES ($list[$i],$par[id])";//new value at root
                      mysql_query($x);
                      $par1= mysql_query("SELECT id FROM node where data=$list[$i]");
                      $par=mysql_fetch_array($par1);
                  }
              }
          }
      }
  
  $abc="";
  
  }
  mysql_close($con);
  
  
  ?&gt;
  </code></pre>
  
  <p>errors</p>
  
  <p>this code seems to be working fine however i keep getting this </p>
  
  <pre><code>error 
  Parse error: syntax error, unexpected T_INC, expecting ')' in C:\xampp\htdocs\new_tree_sql.php on line 37
  </code></pre>
  
  <p>can anyone tell be how to get rid of it and wats the error all abt?????</p>