1
I have a column descri_produto
which would be the product description.
The problem is that I am not able to separate the description in array.
$cat = $_POST['categoria'];
$sql= "SELECT DISTINCT descri_produto, cat_produto FROM produtos WHERE cat_produto LIKE '".$cat."'";
$result= mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)){
print_r(explode(',',$row['descri_produto']));
}
}
Example row of the product description column
Espessura: 6mm,Cor: Incolor
At the moment it’s returning:
Array
(
[0] => Espessura: 6mm
[1] => Cor: Incolor
)
and I need something like:
Array
(
[Espessura] => 6mm
[Cor] => Incolor
)
You can play in another array the position 0 as key and the position 1 as value.
$arr1 = explode(',',$row['descri_produto']);
and then$arr2 = array($arr1[0]=>$arr1[1])
– Don't Panic