title: Looping issue in fetching and display data in php
body: <p>I have 24 records in database table. <br>I want to display 6 records in each particular list. So, i need 4 list of records basically.</p>
  
  <p>I have tried this way, refer below code snippet for more details.</p>
  
  <pre><code> &lt;?php
          $homeBrands1 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.HOME_LOGO,b.STATUS,m.ID,m.TITLE,m.LOGO FROM cms as b
                        INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=1");
          $homeResult1 =mysql_fetch_array($homeBrands1);
  
          $homeBrands3 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
                        INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=3");
          $homeResult3 =mysql_fetch_array($homeBrands3);
  
          $homeBrands2 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
                        INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=2");
          $homeResult2 =mysql_fetch_array($homeBrands2);
  
          $homeBrands4 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
                        INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=4");
          $homeResult4 =mysql_fetch_array($homeBrands4);
  
          $homeBrands5 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
                        INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=5");
          $homeResult5 =mysql_fetch_array($homeBrands5);
  
          $homeBrands6 =mysql_query("SELECT b.MASTER_ID,b.IMAGES,b.PAGE,b.STATUS,b.HOME_LOGO,m.ID,m.TITLE,m.LOGO FROM cms as b
                        INNER JOIN master as m on m.ID=b.MASTER_ID WHERE b.PAGE='homebrands' AND b.POSITION=6");
          $homeResult6 =mysql_fetch_array($homeBrands6);
       ?&gt;  
  
        &lt;div class="brands"&gt;
  
          &lt;div class="main-heading"&gt;
            &lt;h3&gt;Our&lt;br&gt; Brands&lt;/h3&gt;
          &lt;/div&gt;
          &lt;ul id="slider1" style="overflow:hidden;"&gt;
    &lt;li style="margin-left: -19px !important; margin-right:22px !important;"&gt;
  
      &lt;div class="row" style="padding-left:10px !important; margin-left:1px;"&gt;
              &lt;div class="col-sm-4"&gt;
                &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult1['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult1['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult1['HOME_LOGO'];?&gt;" class="img-responsive" alt=""&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img  src="images/home_logos/&lt;?php echo $homeResult1['HOME_LOGO'];?&gt;" class="img-responsive" alt=""&gt;&lt;a href="" onclick="get_details(&lt;?php echo $homeResult1['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult1['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0.4s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult3['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult3['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult3['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult3['TITLE'];?&gt;"&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult3['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult3['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult3['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult3['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
  
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-sm-8"&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-sm-6"&gt;
                    &lt;div class="brand-cat stradivarius wow fadeInUp" data-wow-delay="0.3s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult2['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult2['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult2['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult2['TITLE'];?&gt;"&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult2['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult2['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult2['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult2['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0.5s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult4['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult4['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult4['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult4['TITLE'];?&gt;"&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult4['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult4['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult4['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
  
                  &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult4['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                  &lt;/div&gt;
                   &lt;div class="col-sm-6" style="padding-left:10px;"&gt;
                    &lt;div class="brand-cat gerry wow fadeInUp" data-wow-delay="0.2s"&gt;
                      &lt;img src="images/brands/&lt;?php echo $homeResult5['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult5['TITLE'];?&gt;"&gt;
                      &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult5['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult5['TITLE'];?&gt;"&gt;&lt;/div&gt;
                      &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult5['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult5['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult5['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult5['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                 &lt;div class="row" style="padding:0px !important;"&gt;
                  &lt;div class="col-sm-12"&gt;
                    &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0.5s"&gt;
                      &lt;img src="images/brands/&lt;?php echo $homeResult6['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult6['TITLE'];?&gt;"&gt;
                      &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult6['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult6['TITLE'];?&gt;"&gt;&lt;/div&gt;
                      &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult6['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult6['TITLE'];?&gt;"&gt;&lt;a href="" onclick="get_details(&lt;?php echo $homeResult6['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                  &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult6['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
               &lt;div style="clear:both"&gt;&lt;/div&gt;
            &lt;/div&gt;
          &lt;div style="clear:both"&gt;&lt;/div&gt;
    &lt;/li&gt;
  
     &lt;li style="margin-left: -19px !important; margin-right:22px !important;"&gt;
  
    &lt;div class="row" style="padding-left:10px !important; margin-left:1px;"&gt;
              &lt;div class="col-sm-4"&gt;
                &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult1['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult1['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult1['HOME_LOGO'];?&gt;" class="img-responsive" alt=""&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img  src="images/home_logos/&lt;?php echo $homeResult1['HOME_LOGO'];?&gt;" class="img-responsive" alt=""&gt;&lt;a href="" onclick="get_details(&lt;?php echo $homeResult1['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult1['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0.4s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult3['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult3['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult3['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult3['TITLE'];?&gt;"&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult3['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult3['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult3['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult3['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
  
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-sm-8"&gt;
                &lt;div class="row"&gt;
                  &lt;div class="col-sm-6"&gt;
                    &lt;div class="brand-cat stradivarius wow fadeInUp" data-wow-delay="0.3s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult2['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult2['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult2['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult2['TITLE'];?&gt;"&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult2['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult2['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult2['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult2['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0.5s"&gt;
                  &lt;img src="images/brands/&lt;?php echo $homeResult4['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult4['TITLE'];?&gt;"&gt;
                  &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult4['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult4['TITLE'];?&gt;"&gt;&lt;/div&gt;
                  &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult4['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult4['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult4['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
  
                  &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult4['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="col-sm-6" style="padding-left:10px;"&gt;
                    &lt;div class="brand-cat gerry wow fadeInUp" data-wow-delay="0.2s"&gt;
                      &lt;img src="images/brands/&lt;?php echo $homeResult5['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult5['TITLE'];?&gt;"&gt;
                      &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult5['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult5['TITLE'];?&gt;"&gt;&lt;/div&gt;
                      &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult5['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult5['TITLE'];?&gt;"&gt;&lt;a href="#" onclick="get_details(&lt;?php echo $homeResult5['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                    &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult5['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
               &lt;div class="row" style="padding:0px !important;"&gt;
                  &lt;div class="col-sm-12"&gt;
                    &lt;div class="brand-cat wow fadeInUp" data-wow-delay="0.5s"&gt;
                      &lt;img src="images/brands/&lt;?php echo $homeResult6['IMAGES']; ?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult6['TITLE'];?&gt;"&gt;
                      &lt;div class="brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult6['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult6['TITLE'];?&gt;"&gt;&lt;/div&gt;
                      &lt;div class="overlay"&gt;
                    &lt;div class="overly-brand-name"&gt;&lt;img src="images/home_logos/&lt;?php echo $homeResult6['HOME_LOGO'];?&gt;" class="img-responsive" alt="&lt;?php echo $homeResult6['TITLE'];?&gt;"&gt;&lt;a href="" onclick="get_details(&lt;?php echo $homeResult6['MASTER_ID'];?&gt;);"&gt;&lt;i class="fa fa-long-arrow-right" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/div&gt;
                  &lt;a href="#" onclick="get_details(&lt;?php echo $homeResult6['MASTER_ID'];?&gt;);" class="viewangale"&gt;View more&lt;/a&gt;
                  &lt;/div&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
               &lt;div style="clear:both"&gt;&lt;/div&gt;
            &lt;/div&gt;
         &lt;div style="clear:both"&gt;&lt;/div&gt;
    &lt;/li&gt;
  
    &lt;/ul&gt;
  
        &lt;/div&gt;
  </code></pre>
  
  <p>Can anyone help me on this issue?</p>