I know this question has been answered similar to the previous asked question. I have tried the solutions but it seems that no matter what way I have tried I still can't get this to work. I am not sure is my coding structure is wrong somewhere.
Currently it is displaying the result as:
Cafes (Category)
Starbucks
Cafes (Category)
CoffeeBean
But I wanted it to show:
Cafes (Category)
Starbucks
CoffeeBean
Below is my code:
<?php
$levelArray=array('L1','B1','L2','B2');
foreach ($levelArray as $i=>$level) {
$data='';
$img = "img/".$levelArray[$i];
$result = mysqli_query($con,"SELECT * FROM floor_directory WHERE level='$levelArray[$i]'");
while($row = mysqli_fetch_array($result)){
$data .= '<h1>'.$row['categories'].'</h1>
<ul class="shop_listing clearfix">
<li class="float_left">'.$row['name'].'</li>
<li class="float_right">'.$row['unit_number'].'</li>
</ul>';
}
echo '<div class="swiper-slide">
<img src="'.$img.'" alt="" />
<div class="content_container">'.$data.'</div>
</div>'
}
?>
Any help will be appreciated. Thanks in advance.
$levelArray[$i]inside theforeach()is unnecessary, since you are extracting the values in$level, just use$level