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

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

  1. <div class="row">
  2. <div class="col-md-10 col-md-offset-1">
  3. <div class="row text-center">
  4. <?php
  5. if($_GET[id] == 0)
  6. {
  7. $querysb = mysql_query("SELECT * FROM services WHERE parentid !=0 order by parentid, cid ");
  8. }
  9. else
  10. {
  11. $querysb = mysql_query("SELECT * FROM services WHERE parentid='".$_GET[id]."'");
  12. }
  13. while($rowsb = mysql_fetch_assoc($querysb))
  14. {
  15. if($val == '6' || $val =='10'){
  16. $classname = 'whitebg';
  17. } else {
  18. $classname = 'bg-blue co-white';
  19. }
  20. ?>
  21. <div class="col-md-4 mrgnBtm15">
  22. <div class="<?php echo $classname;?> padding30" style="min-height: 250px">
  23. <h3 class="service-heading">
  24. <?php echo $rowsb['cname'];?>
  25. </h3>
  26. <h4>
  27. RS <?php echo $rowsb['price'];?><br>
  28. </h4>
  29. <div class="mrgnTop15 clearfix"></div>
  30. <a class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
  31. <font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
  32. </div>
  33. </div>
  34. <?php } ?>
  35. </div>
  36. </div>
  37. </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 07: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

    1. <?php
    2. if($_GET[id] == 0)
    3. {
    4. $querysb=mysql_query("SELECT * FROM services WHERE parentid !=0 order by parentid, cid ");
    5. }
    6. else
    7. {
    8. $querysb=mysql_query("SELECT * FROM services WHERE parentid='".$_GET[id]."'");
    9. }
    10. $number_of_records = mysql_num_rows($querysb);
    11. $counter = 1;
    12. while($rowsb=mysql_fetch_assoc($querysb))
    13. {
    14. if($val == '6' || $val =='10'){
    15. $classname= 'whitebg';
    16. }else{
    17. $classname= 'bg-blue co-white';
    18. }
    19. //if($number_of_records %3 ==1 && $counter == $number_of_records)
    20. if(($number_of_records == 5 || $number_of_records == 7) && $counter == $number_of_records)
    21. $col_class = "col-md-12";
    22. else
    23. $col_class = "col-md-4";
    24. ?>
    25. <div class="<?php echo $col_class;?> mrgnBtm15">
    26. <div class="<?php echo $classname;?> padding30" style="min-height: 250px">
    27. <h3 class="service-heading">
    28. <?php echo $rowsb['cname'];?>
    29. </h3>
    30. <h4>
    31. RS <?php echo $rowsb['price'];?><br>
    32. </h4>
    33. <div class="mrgnTop15 clearfix"></div>
    34. <a class="btn bg-orange co-white" href="<?php echo MYWEBSITE;?>servicedetail/<?php echo to_prety_url($rowsb['cname']).'-'.$rowsb['cid'];?>.html">
    35. <font style="size:14px; color:#000; font-weight:bolder;font-family: "Open Sans";">Register</font></a>
    36. </div>
    37. </div>
    38. <?php
    39. $counter++;
    40. } ?>
    41. </div>
    42. </div>
    43. </div>

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部