title: how do I loop inside a loop with PHP in MySQL?
body: <p>table <code>persons</code></p>
  
  <pre><code>name  |   details
  ------------------
  mathew| tax,home,car,insurance
  john  | job,tax,employ
  neil  | tax,home,car,job
  yancy | consultant,rent,family
  lucy  | home,car,insurance
  </code></pre>
  
  <p>I want loop through this table and search with details then saved result to another table called <code>persons1</code></p>
  
  <pre><code>name  |   names
  ------------------
  mathew| neil,lucy,john
  neil  | mathew,lucy,john
  john  | mathew,lucy,neil
  </code></pre>
  
  <p>so far I coded something like below but not working</p>
  
  <pre><code>mysql_connect("localhost", "root", "pass"); 
  mysql_select_db("database");
  $query = "SELECT * FROM persons"; 
  $result  = mysql_query($query); 
  while($r = mysql_fetch_array($result)) 
  { 
      $exp = explode(",",$r["details"]);
      $sql = mysql_query('SELECT * FROM persons WHERE MATCH (tags) AGAINST ("+$exp[0]" "+$exp[1]" "+$exp[2]" IN BOOLEAN MODE)'); 
      $result = array(); 
      while($row = mysql_fetch_assoc($sql))
      {   
          array_push($result,$row['name']);
          $name = implode(",",$result);   
          mysql_query("INSERT INTO person_new (name,names) VALUES (\"".$r["name"]."\", \"".$name."\")");
      } 
  }
  </code></pre>
  
  <p>IT is very sad that nobody can give an answer to my question about my code. instead of looking into my design I request you to look into my code and tell me where I made a mistake..i am doing something different than what it sees and this is why I request you to check my code...</p>