如何在幻灯片中限制时获取数据

时间:2017-03-04 09:35:58

标签: php mysql while-loop

我正在使用幻灯片。我想从数据库中获取幻灯片信息。我的幻灯片结构在第一张幻灯片中,第二张幻灯片中有3条记录,有3条记录,并且记录从后端添加,因此记录正在增加,所有这些记录我想在幻灯片中获取3条记录的分段。我如何从数据库中获取那些记录,并将while循环放在php文件中,我使用的源是

<div class="flexslider">
<ul class="slides">
<?php 

$result = mysql_query('select * from facilities_home');
while($record = mysql_fetch_assoc($result))
{
?>
<li>

<div class="test-one">

<div class="col-md-4 test-left">
<img src="images/test-1.png" alt="" class="mg" />
<p>Cable TV in each Room</p>
<h4>Dec-2010</h4>
</div>
<div class="col-md-4 test-left">
<img src="images/test-3.png" alt="" class="mg" />
<p>30 kVA generator for power backup</p>
<h4>Feb-2011</h4>
</div>
<div class="col-md-4 test-left">
<img src="images/test-2.png" alt="" class="mg"/>
<p>Air conditioner in Double Occupancy Rooms</p>
<h4>Mar-2011</h4>
</div>
<div class="clearfix"></div>
</div>
</li>
<?php
}
?>
<li>
<div class="test-one">
<div class="col-md-4 test-left">
<img src="images/test-4.png" alt="" class="mg"/>
<p>Refrigerator in each Room</p>
<h4>April-2013</h4>
</div>
<div class="col-md-4 test-left">
<img src="images/test-5.png" alt="" class="mg"/>
<p>Recreation Room at the resort, which is a "first in class" amenity.It has got 2 Carrom Boards, Table Tennis, Mini Pool Table, Chess, Magnetic Dart Board etc. </p>
<h4>Aug-2013</h4>
</div>
<div class="col-md-4 test-left">
<img src="images/test-6.png" alt="" class="mg"/>
<p>24 x 7 Hot water in Double Occupancy Rooms</p>
<h4>April-2016</h4>
</div>
<div class="clearfix"></div>
</div>
</li>
<li>
<div class="test-one">
<div class="col-md-4 test-left">
<img src="images/test-7.png" alt="" class="mg"/>
<p>Intercom facility in Double Occupancy Rooms</p>
<h4>April-2016</h4>
</div>
<div class="col-md-4 test-left">
<img src="images/test-8.png" alt="" class="mg"/>
<p>2 Sea facing Cottages developed</p>
<h4>Nov-2016</h4>
</div>

<div class="clearfix"></div>
</div>
</li>
</ul>
</div>

there is a slider in which is want to fetch a result

有一个滑块想要获取结果请帮帮我。

1 个答案:

答案 0 :(得分:0)

它应该是while循环,因为只需你可以这样做:

<?php 
    $result = mysql_query('select * from facilities_home');
    $records = mysql_fetch_assoc($result);
    $newRecords = array_chunk(records, 3);

    foreach($newRecords as $treeRecords){
        foreach($treeRecords as $record){?>
            <div class="col-md-4 test-left">
                <img src="images/test-1.png" alt="" class="mg" />
                <p><?= $record['content']?></p>
                <h4><?= $record['date']?></h4>
            </div>
<?php 
        }
    }
?>

php manual了解array_chuncks()的更多信息。