Inserting multiple array values in mySQL database

后端 未结 3 1939
-上瘾入骨i
-上瘾入骨i 2021-01-28 15:43

I have two PHP variables, both strings:

$friendslist = \"2323443,7245,284683,345123,8456234,95432\"

$id = \"10288272\";

The structure of the t

3条回答
  •  深忆病人
    2021-01-28 16:11

    $comma  = "";
    $values = "";
    $array  = explode(",",$friendslist);
    foreach ($array as $friendid) {
      $values .= $comma."($id,$friendid)";
      $comma = ",";
    }
    $sql = "INSERT INTO UserLinks (User_1, User_2) VALUES $values"
    

提交回复
热议问题