I have few fields that matches one field. for eample I have the fiels size as an attribute but its has many fields that match to it. I want to echo something like: size: s, m, l, xl, xxl... but when I print it, it goes like: size: s size: m size: l size: xl..
how can I print it correctly? code:
<?php
// Create connection
$conn = new mysqli('localhost', 'root','','catalog');
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql="SELECT DISTINCT categories.title AS title_categories , attributes.title AS title_attributes, labels_atr.title AS title_labels_atr
FROM categories
INNER JOIN attributes ON attributes.id=categories.id
INNER JOIN labels_atr ON labels_atr.id_atr=categories.id
GROUP BY labels_atr.title
";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
extract($row);
echo "category: ".$title_categories.",attributes: ".$title_attributes."<BR>";
echo "labels_atr: ".$title_labels_atr."<BR>";
}
}
else {
echo "0 results";
}
$conn->close();
?>
output:
category: Pants,attributes: Size
labels_atr: 32X32
category: Pants,attributes: Size
labels_atr: 32X34
category: Pants,attributes: Size
labels_atr: 32X36
category: Pants,attributes: Size
labels_atr: 34X32
category: Pants,attributes: Size
labels_atr: 34X36
category: Pants,attributes: Size
labels_atr: 36X32
category: Sale,attributes: Size
labels_atr: L
category: Sale,attributes: Size
labels_atr: M
category: Sale,attributes: Size
labels_atr: S
category: Sale,attributes: Size
labels_atr: XL
category: Sale,attributes: Size
labels_atr: XS
category: Sale,attributes: Size
labels_atr: XXL
category: Shirts,attributes: Color
labels_atr: Black
category: Shirts,attributes: Color
labels_atr: Blue
category: Shirts,attributes: Color
labels_atr: Grey
category: Shirts,attributes: Color
labels_atr: Orange
category: Shirts,attributes: Color
labels_atr: Red
category: Shirts,attributes: Color
labels_atr: White
category: Shirts,attributes: Color
labels_atr: Yellow