0

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>
Attachments 11.png 70.09 KB
4
Contributors
12
Replies
43
Views
3 Years
Discussion Span
Last Post by thirsty.soul
0

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

Edited by thirsty.soul

0

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.

0

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.

0

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

Edited by malatamil: 3

0

**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

0

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 }
 ?>
0

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

This question has already been answered. 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.