I have a gallery in grid.
For eg: https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSegNVXMSnTRzHETnAjZXCd6siwHQysMXc_jp1OyiSDie2_9jhsIg

Each row can cont max of 4 images.

I have written while loop.
i want to get the total count of images in each row

For eg: row1 -> 4 (images)
row2 -> 3 (images)


   <div class="main_bg">
   <div class="top_bg1">
   <div class="">
          <div class="main">

       <div class="top_main">
              <h1>Today's Offer</h1>
              <div class="clear"></div>

    $query1 = mysql_query("select * from offer");
    $x = 0;
    while($row = mysql_fetch_array($query1)){    

             <div class="grids_of_3">

        <!-- start grids_of_3 -->

        <div class="grid1_of_3">
        <a href="offer_details.php?fid=<?php echo $row['offer_id']; ?>"> 
            <?php echo "<img src=admin/offer/".$row['image']." />"; ?>
            <h4><?php echo $row['offer_title']; ?></h4>
            <span class="price"><?php echo 'Rs: '.$row['price']; ?></span> <span class="price1 bg">Hot Sale</span> 
                <h3><a href="offer_details.php?fid=<?php echo $row['offer_id']; ?>" class="myButton">Add to cart</a></h3>


                echo $x;
                  echo '<div class="clear"></div></div>';


   }  // while


         <!-- start grids_of_3 -->


<!-- start footer -->


Edited by diafol: reformatted code

2 Years
Discussion Span
Last Post by matrixdevuk

You can store number of images per row in an array (this is untested, just a concept):

// between lines 17 and 18 - initialize variables
$rowNo = 1;
$imagePerRow = array();

// between lines 44 and 45 - assign current value for that row
imagePerRow[$rowNo] = $x;

// on line 49 - increase row counter

To make it more efficient, store only a number for the last row, since all other rows have 4 images. The last row will have 4 or less images.

Edited by broj1


It seems like @broj1 has got what you need, though I am not 100% sure on what it is you need done (I'm tired). If it's not what you want just reply and more examples and help will come.

Edited by matrixdevuk

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.