晚上好。
此构造在表格中显示值,按字母顺序对它们进行排序。例如,如果单击D链接,则只显示带字母D的名称,依此类推。
PHP代码:
<?php
include ('engine/api/api.class.php');
$table = 'dle_post';
$fields = 'xfields';
$where = 'approve=1';
$multirow = 1;
$start = 0;
$limit = 0;
$xfield = 'actor';
$time = '14000';
$tr_new = 0;
$xfields = $dle_api->load_from_cache ($fields, $time, $xfields);
if( !$xfields ) {
$xfields = $dle_api->load_table ($table,$fields,$where,$multirow,$start,$limit);
$dle_api->save_to_cache ( xfields, $xfields);
}
$stack = array();
foreach($xfields as $value){
if($value[xfields]){
$row = xfieldsdataload($value[xfields]);
if($row[$xfield]){
$rowdata = explode( ",", $row[$xfield]);
foreach($rowdata as $value){
if($value){
$value = trim($value);
array_push($stack, $value);
asort($stack);
}
}
}
}
}
$stack = array_count_values($stack);
foreach($stack as $key => $count){
if($tr_new === 0){
echo '<tr class="new">';
}
echo "<td class='blok'>";
echo "<a href=/" . $xfield . "/";
echo $key;
echo " target='_blank' rel='noopener'>";
echo $key;
echo "</a>";
echo "<span>";
echo "(" . $count . ")";
echo "</span>";
echo "</td>";
$tr_new++;
if($tr_new === 1){
echo '</tr>';
$tr_new = 0;
}
}
JQuery的:
$(function () {
var _alphabets = $('.alphabet > a');
var _contentRows = $('#countries-table tbody tr');
_alphabets.click(function () {
var _letter = $(this), _text = $(this).text(), _count = 0;
if(_text == 'all') _text = '.';
_alphabets.removeClass("active");
_letter.addClass("active");
_contentRows.hide();
_contentRows.each(function (i) {
var _cellText = $(this).children('td').eq(0).text();
if (RegExp('^' + _text).test(_cellText)) {
_count += 1;
$(this).fadeIn(400);
}
});
});
});
在页面中:
<div class="alphabet">
<a class="first" href="#">All</a>
<a href="#">A</a>
<a href="#">B</a>
<a href="#">C</a>
...
<a class="last" href="#">Z</a></div>
<div id="conutries">
<table id="countries-table">
<tbody>
{include file="/code.php"}
</tbody>
</table>
</div>
</div>
一切正常,但我遇到了这样的问题 - 事实证明只能输出一行tr中的一个值...
当我尝试将4个td值放到tr行if($tr_new === 4)
时 - 它们不按字母顺序排序,它们只显示如下:
什么错了?需要使这段代码对我有用吗? 提前感谢您的帮助!