title: Inserting multiple array values in mySQL database
body: <p>I have two PHP variables, both strings:</p>
  
  <pre><code>$friendslist = "2323443,7245,284683,345123,8456234,95432"
  
  $id = "10288272";
  </code></pre>
  
  <p>The structure of the table I am concerned with is as follows:</p>
  
  <p>Table Name: UserLinks</p>
  
  <pre><code>link_id   user_1    user_2
  </code></pre>
  
  <p>I need to insert these values into the table so that user_1 is always $id, and user_2 is the members of the $friendslist string. It will look like this:</p>
  
  <pre><code>link_id   user_1    user_2
  1         10288272  2323443
  2         10288272  7245
  3         10288272  284683
  4         10288272  345123
  </code></pre>
  
  <p>I know the basics of inserting many values, where in this cause I would use:</p>
  
  <pre><code>mysql_query("INSERT INTO UserLinks (User_1, User_2) VALUES ('10288272','2323443'),('10288272','7245'),('10288272','284683')");
  </code></pre>
  
  <p>But the only way I can think to of to write this (as these values are obviously not the actual values inserted) is something like this:</p>
  
  <pre><code>$friendarray = explode(",", $friendslist);
  
  for ($n = 0; $n &lt; count($friendarray); $n++) {
        $friendidpush = "('".$id."','".$friendarray[$n]."'),";
        array_push($frienduserarray, $friendidpush);
  }
  </code></pre>
  
  <p>Followed by converting the $frienduserarray to a string, and then including it in my query. This returned an error for me, and I do not think this is the right way to do it... but I am struggling to find a solution online. </p>