简体   繁体   English

n之后改变风格。 结果 - PHP

[英]Changing style after n no. of results- PHP

Hi i use PHP to fetch data from database using while loop. 您好我使用PHP使用while循环从数据库中获取数据。 A class paid or unpaid is applied through database field value. 通过数据库字段值应用付费或未付款的类。 Paid members are shown 2 members per line and unpaid 3 per line and that are working well for me. 付费会员每行显示2个成员,每行显示3个未支付成员,这对我来说效果很好。 But a small little issue is when paid members are ended, i want a line-break then display unpaid members from a new line 3 in a row. 但是一个小小的问题是当付费会员结束时,我想要一个换行符,然后连续显示来自新行3的未付费成员。 How i can do that ? 我怎么能这样做?

HTML HTML

<div class="main paid">
  ABC
</div>
<div class="main paid">
  ABC
</div>
<div class="main paid">
  ABC
</div>
<div class="main unpaid">
  ABC
</div>
<div class="main unpaid">
  ABC
</div>
<div class="main unpaid">
  ABC
</div>
<div class="main unpaid">
  ABC
</div>

CSS CSS

.main{
  float:left;
  margin-bottom:30px;
  border:1px solid #ddd;
}
.paid{
  width:49%;
}
.unpaid{
  width:32%;
}

Working Fiddle: https://jsfiddle.net/qzxyyo2x/1/ 工作小提琴: https//jsfiddle.net/qzxyyo2x/1/

Here paid or unpaid are table values fetched from database. 付费或未付款是从数据库中获取的表值。 Width is applied to them. 宽度适用于它们。 I want to add a "line-break" when paid members are ended to display unpaid members 3 in a row from the next row. 我希望在付费会员结束时添加“换行符”,以显示下一行连续3行的未付费成员。 In this question i need a line-break after 3 results. 在这个问题中,我需要在3个结果后进行换行。 and if paid members are 2,4,5,6 or whatever. 如果付费会员是2,4,5,6或其他什么。 I need a line-break after displaying all paid members. 显示所有付费会员后我需要换行。

Thanks in advance.... 提前致谢....

You could use some clearfix code to trigger unpaid classes to break with clear: both; 您可以使用一些clearfix代码来触发未付费的类以clear: both; however if applied to the entire .unpaid class, all unpaid classes would be on their own line. 但是如果应用于整个.unpaid类,所有未付费的类都将在他们自己的行上。

Incorrect Demo: https://jsfiddle.net/qzxyyo2x/2/ 不正确的演示: https//jsfiddle.net/qzxyyo2x/2/

A quick solution would be a new class called .clearfix . 一个快速的解决方案是一个名为.clearfix的新类。 You could use this whenever an unpaid class follows a paid class, but not when an unpaid class follows an unpaid class. 只要非unpaid类跟随paid类,您就可以使用此功能,但是当非unpaid类跟随非unpaid类时则不能。 This logic will have to be done in PHP. 这个逻辑必须在PHP中完成。

Correct Demo: https://jsfiddle.net/qzxyyo2x/3/ 正确的演示: https//jsfiddle.net/qzxyyo2x/3/

An even more elegant solution would involve creating extra div s surrounding each of your rows, but this may involve changing more of your logic than just one class. 更优雅的解决方案是在每个行周围创建额外的div ,但这可能涉及更改逻辑而不仅仅是一个类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM