1
Good afternoon I’m finalizing a script that will make some updates on our website I have an array that at the beginning contains all the clients of the company and as the script is run, some are removed. In the end, the remaining customers in the array should be updated with the INACTIVE Status on our website. The problem is that some remaining records in this array are returning this error message.
Follows excerpt from the code -
echo "Existem ".count($array_codigos) . " registros no banco SQL<br>";
arsort($array_codigos);
for($iy = 0; $iy <= count($array_codigos); $iy++){
$num++;
/******************************************************************
* Deleta os clientes inexistentes do banco DBF do banco SQL *
* Tabelas: Clientes, Contratos, Pagamentos, Boletos e Usuários *
******************************************************************/
$codigo_cliente = $array_codigos[$iy];
// TABELA CLIENTE
$consulta_cli = mysql_query("SELECT * FROM clientes WHERE cod_cliente = '$codigo_cliente'");
$num_cli = mysql_num_rows($consulta_cli);
if($num_cli != 0){
$array_cli = mysql_fetch_array($consulta_cli);
$status = $array_cli['status_cli'];
$nome_cliente = $array_cli['nome_cliente'];
if($status_cli != 'I'){
$update_inativo = mysql_query("UPDATE clientes SET status_cli = 'I' WHERE cod_cliente = $codigo_cliente");
if($update_inativo){
$inativos++;
echo "$iy - $codigo_cliente - $nome_cliente não existe no DBF - Atualizado para Inativo<br>";
$delete_users = mysql_query("DELETE FROM usuarios WHERE cod_cliente = $codigo_cliente");
}else{
$erro = mysql_error();
echo "$erro";
}
}
}
}
The code is quite extensive, if necessary, put other information.
Thank you in advance.
What would line 779 be? Deducing the error, the problem would be here: '$codigo_client = $array_codigos[$iy]'. If users, their array, is not sorted 0, 1, 2, 3.... This will occur.
– Inkeliz
In the second line of your code (here posted!), edit the
arsort($array_codigos);
for$array_codigos = array_values ($array_codigos)
. Check if the same problem persists.– Inkeliz