I have the following code, but it is not working and I can not find the error.
I need to display the 3 lines (123), which are found in $fetch['list_carac']
.
<?php
include 'conect.php';
$sql = "SELECT list_carac FROM select_carac WHERE id_produto = 1";
$exec = $con->query( $sql ) or exit( $con->error );
$fetch = mysqli_fetch_assoc($exec);
$fetch = str_replace( ",", "", $fetch);
echo($fetch['list_carac']);//aqui a saída é 123
foreach($fetch as $value){
$sql = "SELECT nome_carac FROM carac WHERE id_carac = $value";
$exec = $con->query( $sql ) or exit( $con->error );
$row = mysqli_fetch_assoc($exec);
echo $row["nome_carac"];
}
?>
If I take out foreach
and add id
manually it returns the record that is in the nome_carac
field. Otherwise it does not give error, but only shows the 1st output echo($fetch['list_carac']);//aqui a saída é 123
.