i want to display 3 data per row and n number of rows. someone help me to do this.

<div class="top-box">
        <?php include("config.php");
        $sub2_category_id = $_GET['sub2product_id'];
        $sub2_category_name = $_GET['sub2product_name'];
        echo '<h2 class="head">'.$sub2_category_name.'</h2>';
        $sql = mysql_query("SELECT p.`product_id`, p.`brand_name`, p.`brand_path`, p.`sub2_category_id`, p.`sub_category_id`, p.`main_category_id`, p.`date`,ba.`brand_amount_id`, ba.`available_pack`, ba.`mrp_amount`, ba.`our_price`, ba.`product_id` FROM `product` p JOIN brand_amount ba ON ba.product_id=p.product_id WHERE p.sub2_category_id='$sub2_category_id' GROUP BY  p.`brand_name`");
        $num_rows = mysql_num_rows($sql);

        while($row = mysql_fetch_array($sql))
        {
            ?>

            <div class="col_1_of_3 span_1_of_3"> 
               <a href="single.html">
                <div class="inner_content clearfix">
                    <div class="product_image">
                        <img src="web/<?php echo $row['brand_path']; ?>" alt=""/>
                    </div>

                    <div class="price">
                       <div class="cart-left">
                            <p class="title"><?php echo $row['brand_name']; ?></p>
                            <div class="price1">
                              <span class="reducedfrom">Rs. <?php echo $row['mrp_amount']; ?></span>
                              <span class="actual">Rs. <?php echo $row['our_price']; ?></span>
                            </div>
                        </div>
                        <div class="cart-right"> </div>
                        <div class="clear"></div>
                     </div>              
                   </div>
                 </a>
                </div>

                <div class="clear"></div>
            <?php  } ?>

     </div>

what output do you get ? with this code ?? And also share the generated html..

am getting like this

it means for each loop this code is executed. which generates a new row.
<div class="col_1_of_3 span_1_of_3">

Use for Loop to increment Like class="col_2_of_3 span_2_of_3" and soo on.

thanks but <div class="top-box">
creates new row with 3 fields

Member Avatar for diafol

WHen you say row - do you want to make a table? If not then you're probably into display: inline_block (css).

You can do something like set the widths to 33% or whatever. Many ways to do this. Implementing a grid system may be the easiest, as it can be shoehorned to be responsive quite easily.

no its in div only. its a responsive site so i d't know how to manage these css. in for loop is their any possible way to do

**Use This **

<div class="section group">
    <div class="col span_1_of_3">
    This is column 1
    </div>
    <div class="col span_1_of_3">
    This is column 2
    </div>
    <div class="col span_1_of_3">
    This is column 3
    </div>
</div>

Click Here

normal html ok. i want in dynamic loop

Try This. It will Work. this will increment your css class.

<div class="top-box">

    <?php
$a=1;
$b=1;

 for($i=1;$i<8;$i++)
{


?>
    <?php  print "<div class='col_". $a++ ."_of_3 span_". $b++ ."_of_3'>";?>
               <a href="single.html">
                <div class="inner_content clearfix">
                    <div class="product_image">
                        <img src="web/<?php echo $row['brand_path']; ?>" alt=""/>
                    </div>
                    <div class="price">
                       <div class="cart-left">
                            <p class="title"><?php echo $row['brand_name']; ?></p>
                            <div class="price1">
                              <span class="reducedfrom">Rs. <?php echo $row['mrp_amount']; ?></span>
                              <span class="actual">Rs. <?php echo $row['our_price']; ?></span>
                            </div>
                        </div>
                        <div class="cart-right"> </div>
                        <div class="clear"></div>
                     </div>              
                   </div>
                 </a>
                </div>
                <div class="clear"></div>

     </div>
     <?php 
     if ($a==4) 
     {
        $a=1; 
     }
      if ($b==4) 
     {
        $b=1; 
     }
     ?>
 <?php }
 ?>

Initialize the loop terminator with the number of rows in your database.. :)
I have terminated loop after 8 ..!

thanks its working

Mark thread as solved brother.
It will help other users to sought out easily ..!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.