If there is a value in the sql query, it does not take the value of the query in the variable $acd0
while (true) {
$t= "SELECT MAX(id) AS id FROM accidente";
$query2=mysqli_query($db,$t);
while($acd=mysqli_fetch_array($query2))
$last= current($last_id);
// $acd_1=current($acd);
$ls=(( $last !== false) ? $last : ", ");
// $acd2=(( $acd_1 !== false) ? $acd_1 : ", ");
$valores3='("'.$acd[0].'","'.$ls.'"),';
$valoresQ3= substr($valores3, 0, -1);
$acd_impl=$db->query("INSERT INTO implicado_acd (id_acd, id_implicado) VALUES $valoresQ3");
$sqlRess1=$db->query($acd_impl) or mysql_error();
$last = next($last_id);
//$acd_1= next($acd);
if($last === false) break;
echo "string".$acd[0];
} }