dou44364983 2015-05-21 18:55
浏览 13

PDO:对于每一定数量的行

I have a script im working on for a project, I would like to obtain information from the database through my PDO connection. What i would like to achieve is the following:

Basically its a eCommerce template where you view the products on the page, each row can only show 3 products at a time (template style). So for short i would like to achieve that 3 products is shown per row (if there is more than 3 products per category, it should create a another loop to display the other products in the next row "template style").

Here is the template i am using:

<div class="top-box">
<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="images/pic.jpg" alt=""/>
</div>
<div class="sale-box"><span class="on_sale title_shop">New</span></div> 
                <div class="price">
                   <div class="cart-left">
                        <p class="title">Lorem Ipsum simply</p>
                        <div class="price1">
                          <span class="actual">$12.00</span>
                        </div>
                    </div>
                    <div class="cart-right"> </div>
                    <div class="clear"></div>
                 </div>             
               </div>
             </a>
            </div>
           <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="images/pic1.jpg" alt=""/>
                </div>
                <div class="price">
                   <div class="cart-left">
                        <p class="title">Lorem Ipsum simply</p>
                        <div class="price1">
                          <span class="actual">$12.00</span>
                        </div>
                    </div>
                    <div class="cart-right"> </div>
                    <div class="clear"></div>
                 </div>             
               </div>
               </a>
            </div>
            <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="images/pic2.jpg" alt=""/>
                </div>
                <div class="sale-box1"><span class="on_sale title_shop">Sale</span></div>   
                <div class="price">
                   <div class="cart-left">
                        <p class="title">Lorem Ipsum simply</p>
                        <div class="price1">
                          <span class="reducedfrom">$66.00</span>
                          <span class="actual">$12.00</span>
                        </div>
                    </div>
                    <div class="cart-right"> </div>
                    <div class="clear"></div>
                 </div>             
               </div>
               </a>
            </div>
            <div class="clear"></div>
        </div>

The fist 3 products must be as the code above, then loop if there is more products with the same style.

  • 写回答

2条回答 默认 最新

  • duangou2046 2015-05-21 19:04
    关注

    Here's a little solution.

    try
    {
    ..your retrieving statements
    }
    catch
    {
    ../
    }
    $count = $variable->rowCount();
    if($count >= 3)
    {
    ..//only one row
    }
    else
    {
    $divisions = $count / 3;
    for($i=1;$i<=$divisions;$i++)
    {
    //echo the products etc
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭