title: Loop through an array to unset a known value and implode to sql
body: <p>I have two set of arrays in different MYSQL table. This what I want to do</p>
  
  <pre><code>               What I Want TO Do
     TABLE_ONE            connect to the table.
                          get the value we want from session_id
                          THEN get the array associated with the value (session_id)
                          explode the array to get individual values.
                          NOW::::: - GO TO TABLE_TWO
  
     TABLE_TWO            Go straight to the first value from array (TABLE_ONE)
                          Explode the array associated with it.
                          Delete the number that's equal to the session_id
                         _____________________________________________________
                         And so fort....
  </code></pre>
  
  <p>More visual explanation below:
  <code>session_id = 4</code></p>
  
  <p>TABLE_ONE:</p>
  
  <pre><code>   id            array1
     1             4
     2             1
     3             2,5
     4             1,3,4,5
     5             4,5
  </code></pre>
  
  <p>TABLE_TWO:</p>
  
  <pre><code>   id            array2
     1             4,6,9,2
     2             3,7,8,2
     3             7,12,4,9
     4             1,5,4,8
     5             3,6,12,3,5,4
  </code></pre>
  
  <p>So, because <code>session_id = 4</code>, we go to TABLE_ONE <code>id 4</code>. The array of id-4 is 1,3,4,5.
  So now we know 4 can be found in <code>id 1,3,4,5 of TABLE_TWO</code>
  We should now explode TABLE_TWO's array and delete <code>4</code> from there array. Implode the array and save the new value to database.</p>
  
  <p>THIS IS WHAT I HAVE DONE - it would delete only '4' from them id-3 and delete all the values in id-4. Please help!!</p>
  
  <pre><code>    $SESSION = 4;
      $depSQL = mysql_query("SELECT array1 FROM TABLE_ONE WHERE id='$SESSION' LIMIT 1"); 
  while($row=mysql_fetch_array($depSQL)) { $depARRAY = $row["array1"]; }
  $explodedDEP = explode(",", $depARRAY);
  foreach ($explodedDEP as $key1 =&gt; $value1) {
  
      $stSQL = mysql_query("SELECT array2 FROM TABLE_TWO WHERE id='$value1'"); 
      while($get=mysql_fetch_array($stSQL)) { $stARRAY = $get["array2"];}
      $explodedST = explode(",", $stARRAY);
          foreach ($explodedST as $key2 =&gt; $value2) {
                if ($value2 == $SESSION) {
                        unset($explodedST[$key2]);
                }
          }
           $newST = implode(",", $explodedST);
       $sql = mysql_query("UPDATE TABLE_TWO SET array2 ='$newST' WHERE id='$value2'");
  
  }
  exit();
  </code></pre>
  
  <p>Please help!!! I'm really struggling on it.
  I have tried it for hours now and i havent really got any where.
  I think the problem is with the inserting to database.
  Please help.</p>