点击提交按钮后,我必须使用php simpleXML构建一个分页。
我的XML文件如下所示:
<events>
<event_data>
<club>Club 1</club>
<categoryid>10</categoryid>
<category>WellFit®</category>
<startdate realdate="2013-08-24">1377295200</startdate>
<enddate realdate="2013-09-07">1378504800</enddate>
</event_data>
<event_data>
<club>Club 2</club>
<categoryid>9</categoryid>
<category>Golf</category>
<startdate realdate="2013-08-24">1377295200</startdate>
<enddate realdate="2013-09-07">1378504800</enddate>
</event_data>
<event_data>
<club>Club 3</club>
<categoryid>14</categoryid>
<category>Tennis</category>
<startdate realdate="2013-08-24">1377295200</startdate>
<enddate realdate="2013-09-07">1378504800</enddate>
</event_data>
……
</events>
我的php文件是这样的:
<form action="" method="post">
<div id="slider-range"></div>
<input type="text" name="startdate" style="margin:40px 0 0">
<input type="text" name="enddate" style="margin:40px 0 0">
<div class="chembox_items" style="padding:5px 0 0;">
<div class="golf">
<input type="checkbox" name="checkname[]" value="1">
<span>Golf</span>
</div>
<div class="wassersport">
<input type="checkbox" name="checkname[]" value="9">
<span>Wassersport</span>
</div>
<div class="wellfit">
<input type="checkbox" name="checkname[]" value="10">
<span>WellFit®</span>
</div>
<div class="tennis">
<input type="checkbox" name="checkname[]" value="14">
<span>Tennis</span>
</div>
</div>
<div class="select_club">
<select name="clubname" class="club">
<option value=""> Club auswählen</option>
<option value="Club 1">Club 1</option>
<option value="Club 2">Club 2</option>
<option value="Club 3">Club 3</option>
</select>
</div>
<input type="submit" name="submitClub" value="Submit" />
</form>
<?php
?>
<div id="eventList">
<?php
$startPage = $_GET['page'];
$perPage = 10;
$currentRecord = 0;
$sxe = simplexml_load_file('event.xml');
if($sxe) {
if(isset($_POST['submitClub'])) {
//for checkbox
foreach($_POST['checkname'] as $key => $box){
$checkbox = $_POST['checkname'][$key] = $box;
}
$varClub = $_POST['clubname'];
//echo $varClub;
$varStart = $_POST['startdate'];
$varEnd = $_POST['enddate'];
if($varStart){
$start = strtotime($varStart);
$end = strtotime($varEnd);
$xpath = sprintf(
'//event_data[
(%1$d >= startdate and %2$d <= enddate)
or
(%1$d <= enddate and %2$d >= startdate)
]',
strtotime($varStart),
strtotime($varEnd)
);
foreach($sxe->xpath($xpath) as $item){
?>
<div class="item <?php echo $item->categoryid ?> clearfix">
<div class="left">
<div class="header_data">
<h2><?php echo $item->name ?></h2>
<div class="date"><?php
$startdate = $item->startdate->attributes()->realdate;
$enddate = $item->enddate->attributes()->realdate;
echo date("d.m.Y", strtotime($startdate)) . ' - ' . date("d.m.Y", strtotime($enddate));
?></div>
<div class="club"><?php echo $item->club ?></div>
</div>
</div>
</div>
<?php
}
}
if($checkbox) {
foreach($sxe->xpath('//event_data') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//categoryid[. ="' . $checkbox . '"]');
if($v[0]){
?>
<div class="item <?php echo $item->categoryid ?> clearfix">
<div class="left">
<div class="header_data">
<h2><?php echo $item->name ?></h2>
<div class="date"><?php
$startdate = $item->startdate->attributes()->realdate;
$enddate = $item->enddate->attributes()->realdate;
echo date("d.m.Y", strtotime($startdate)) . ' - ' . date("d.m.Y", strtotime($enddate));
?></div>
<div class="club"><?php echo $item->club ?></div>
</div>
</div>
</div>
<?php }
}
}
//For selectbox
else if($varClub) {
foreach($sxe->xpath('//event_data') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//club[. ="' . $varClub . '"]');
if($v[0]){
?>
<div class="item <?php echo $item->categoryid ?> clearfix">
<div class="left">
<div class="header_data">
<h2><?php echo $item->name ?></h2>
<div class="date"><?php
$startdate = $item->startdate->attributes()->realdate;
$enddate = $item->enddate->attributes()->realdate;
echo date("d.m.Y", strtotime($startdate)) . ' - ' . date("d.m.Y", strtotime($enddate));
?></div>
<div class="club"><?php echo $item->club ?></div>
</div>
</div>
</div>
<?php }
}
} else {
echo 'Keine Events';
}
}
} else {
echo '<p>Die Datei konnte nicht geöffnet werden</p>';
}
?>
</div>
此代码执行以下操作: 用户有3个提交选项。
因此,在用户提交上述3个案例之一后,将显示所选选项的所有事件。结果可能是20个事件现在显示在一个站点上。
因此,我不想在一个页面上列出事件,而是要通过它进行分页。
例如:提交的俱乐部有20个活动,每个页面上应显示5个活动,以便我们有4个页面。
我希望很清楚我想要实现的目标。
我感谢每个人的帮助:)。