douyou1937 2017-08-19 14:54
浏览 91
已采纳

如何在php网页中更改某些内容面板的<div>属性?

<div class="row">
    <div class="col-md-10 col-md-offset-1">
        <div class="row text-center">

    <?php
    if($_GET[id] == 0)
    {
        $querysb = mysql_query("SELECT  * FROM services WHERE parentid !=0 order by parentid, cid ");
    }
    else
    {
        $querysb = mysql_query("SELECT  * FROM services WHERE parentid='".$_GET[id]."'");
    }
    while($rowsb = mysql_fetch_assoc($querysb))
    {
        if($val == '6' || $val =='10'){
            $classname = 'whitebg';
        } else {
            $classname = 'bg-blue co-white';
        }
    ?>

          <div class="col-md-4 mrgnBtm15">
            <div class="<?php echo $classname;?> padding30" style="min-height: 250px">
             <h3 class="service-heading">
                <?php echo $rowsb['cname'];?>
              </h3>
              <h4>
                RS <?php echo $rowsb['price'];?><br>
              </h4>
              <div class="mrgnTop15 clearfix"></div>

              <a  class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
                  <font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>

            </div>
          </div>
<?php } ?>
        </div>
      </div>
    </div>

I am working on a dynamic website. here is the code of a particular page. In this page there is a div section with class="col md-4". If the number of content panel in that division appears to 5 or 7 in that case I want only the last panel (i.e 5th and 7th) to be in full column (col-12). What should I do?

  • 写回答

1条回答 默认 最新

  • drdyszuy488152 2017-08-19 15:08
    关注

    Since you are using col-md-4, 3 divs will be shown each row. So I think what you are looking for is a way to make the last div full width if its going to be alone in its row. In that case, you will need to make it col-md-12 on 4th (not 5th) and 7th and 10th records and so on. This is exactly what the following code does,

    I think what you want to do is show the

        <?php
        if($_GET[id] == 0)
        {
        $querysb=mysql_query("SELECT  * FROM services WHERE parentid !=0 order by parentid, cid ");
        }
        else
        {
        $querysb=mysql_query("SELECT  * FROM services WHERE parentid='".$_GET[id]."'");
        }
        $number_of_records = mysql_num_rows($querysb);
        $counter = 1;
        while($rowsb=mysql_fetch_assoc($querysb))
        {
            if($val == '6' || $val =='10'){
                $classname= 'whitebg';
            }else{
                $classname= 'bg-blue co-white';
            }
            //if($number_of_records %3 ==1 && $counter == $number_of_records)
            if(($number_of_records == 5 ||  $number_of_records == 7) && $counter == $number_of_records)
                $col_class = "col-md-12";
            else
                $col_class = "col-md-4";
    
        ?>
    
                  <div class="<?php echo $col_class;?> mrgnBtm15">
                    <div class="<?php echo $classname;?> padding30" style="min-height: 250px">
                     <h3 class="service-heading">
                        <?php echo $rowsb['cname'];?>
                      </h3>
                      <h4>
                        RS <?php echo $rowsb['price'];?><br>
                      </h4>
                      <div class="mrgnTop15 clearfix"></div>
    
                      <a  class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
                          <font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
    
                    </div>
                  </div>
        <?php
        $counter++;
         } ?>
                </div>
              </div>
            </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?