This code is supposed to insert the same row multiple times, but with different values stored in $myArray in the sender field:
$sql = ("SELECT contacts FROM Users WHERE username = '$usernametmp' ");
$result = $conn->query($sql)->fetch(PDO::FETCH_COLUMN);
$myArray = explode(',', $result);
$sql = "INSERT INTO Messages (sender,username,timestamp,msgtype) VALUES (('" . implode("','",$myArray) . "'),'$usernametmp',(CURRENT_TIMESTAMP),'8')";
The contacts indeed are there, but I get this error:
Error: SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)
What I think I understand is wrong is that implode would work across multiple cells in the same column, but is there a way I can do this without using a foreach?