TABLE
id m_id image
1 1 img1.jpg
2 2 img2.jpg
3 1 img11.jpg
4 2 img22.jpg
5 1 img111.jpg
........ etc
What i need is - Get only 2 rows from the table group by m_id as below
//here getting images where m_id=1 and it is not more than 2
<section class='test'>
<div class="n-2">
<img src='img1.jpg'>
</div>
<div class="n-2">
<img src='img11.jpg'>
</div>
</section>
//next fetching images with m_id=2
<section class='test'>
<div class="n-2">
<img src='img2.jpg'>
</div>
<div class="n-2">
<img src='img22.jpg'>
</div>
</section>
......
What i tried is
<?php
$query=$db->query("Select * from gallery order by m_id asc");
$result = $query->fetchAll(\PDO::FETCH_ASSOC);
for ($i=0; $i < count($result); $i+=2) {
?>
<section class='test'>
<div class="n-2">
<img src='<?php $result[$i]['image']; ?>'>
</div>
<div class="n-2">
<img src='<?php $result[$i+1]['image']; ?>'>
</div>
</section>
<?php
}
?>
But i am getting all the fields to the showed section class'test'
, How to get the only 2 rows as showed section class.
Any experts?