gpt4 book ai didi

php - 按列名排序在列表页面上的纯 PHP 中不起作用

转载 作者:行者123 更新时间:2023-11-30 23:23:45 25 4
gpt4 key购买 nike

我在 .分页工作正常,但按列名搜索未按预期工作。这是我的代码:

索引.php

<table>
<tr>
<?php
$page = "";
if (isset($_GET['page'])) {
$page = "&page=" . $_GET['page'] . "";
}
$order = "&order=ASC";
if (isset($_GET['order']) && $_GET['order'] == "ASC") {
$order = "&order=DESC";
}
?>

//带排序记录链接的列名

        <th><a href='index.php?<?php echo $order ?>&orderBy=articleTitle<?php echo $page ?>' >Article Title</a></th>
<th><a href='index.php?<?php echo $order ?>&orderBy=articleSubTitle<?php echo $page ?>' >Article SubTitle</a></th>
</tr>
<?php
$perpage = 2;
if (isset($_GET["page"])) {
$page = intval($_GET["page"]);
} else {
$page = 1;
}
$calc = $perpage * $page;
$start = $calc - $perpage;
$where = "";
if (isset($_GET['orderBy'])) {
$order = "ASC";
if (isset($_GET['order']) && $_GET['order'] == "ASC") {
$order = "DESC";
}
$where.=" ORDER BY " . $_GET['orderBy'] . " " . $order;
}

$result = mysql_query("SELECT * FROM xp_article $where Limit $start, $perpage");
$i = 0;
if (isset($_GET['order']) && $_GET['order'] == "ASC") {
asort($result);
}
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td style='text-align:center'>" . $row['articleTitle'] . "</td>";
echo "<td style='text-align:center'>" . $row['articleSubTitle'] . "</td>";
echo "</tr>";
}
?>

//分页代码

    <tr>
<th colspan="3" class="paging" style="text-align: center">
<?php
if (isset($page)) {
$result1 = mysql_query("SELECT Count(*) As Total FROM xp_article");
$rows = mysql_num_rows($result1);
if ($rows) {
$rs = mysql_fetch_array($result1);
$total = $rs["Total"];
}
$totalPages = ceil($total / $perpage);
if ($page <= 1) {
echo "<span>Prev</span>";
} else {
$j = $page - 1;
echo "<span><a href='index.php?page=$j'>< Prev</a></span>";
}
for ($i = 1; $i <= $totalPages; $i++) {
if ($i <> $page) {
echo "&nbsp;&nbsp;<span><a href='index.php?page=$i' >$i</a></span>";
} else {
echo "&nbsp;&nbsp;<span>$i</span>";
}
}
if ($page == $totalPages) {
echo "&nbsp;&nbsp;<span>Next ></span>";
} else {
$j = $page + 1;
echo "&nbsp;&nbsp;<span><a href='index.php?page=$j'>Next</a></span>";
}
}
?>
</th>
</tr>
</table>

谁能告诉我我错过了什么.... :)

最佳答案

    Hi your code is working good there is no need to bellow code remove it or comment it
if (isset($_GET['order']) && $_GET['order'] == "ASC") {
asort($result);
}

关于php - 按列名排序在列表页面上的纯 PHP 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14331689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com