I want to update a table where column user_id
has values, stored in an array, but I get this error:
Array ( [0] => Array ( [0] => 42S22 [SQLSTATE] => 42S22 [1] => 207 [code] => 207 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'Array'. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid column name 'Array'. ) )
This is my code:
$sql = "
SELECT usuario_id
FROM control_asistencias
WHERE
ano=".$ano." and
mes=".$mes." and
dia".$dia."='T' and
comida_habitual ='T'
";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true) );
}
$usuarios_comida_habitual = array();
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
array_push($usuarios_comida_habitual,$row['usuario_id']);
}
// Una vez que tenemos los usuarios Que han fichado para ese dia hacemos un Update
$sql_update = "
UPDATE VLD_PRESENCIA
SET VLD_PRESENCIA_DIA".$dia." = 'T'
WHERE
VLD_PRESENCIA_CODUSUARIO IN (".$usuarios_comida_habitual.") AND
VLD_PRESENCIA_COMIDA_HABITUAL = 'T'
";
$stmt2 = sqlsrv_query( $conn2, $sql_update);
if( $stmt2 === false ) {
die( print_r( sqlsrv_errors(), true) );
}
else
{
echo 'eureka';
}
Is it possible that the way the array was passed is wrong? Or is it possible to put the condition that I want to implement what userid
should be in that array?
I found this
array_walk($usuarios_comida_habitual , 'intval');
$ids = implode(',', $usuarios_comida_habitual);
i Do this before generating $sql_update