Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:46:57+00:00 2026-06-17T06:46:57+00:00

I have created listing page with pagination and sorting by column name in .

  • 0

I have created listing page with pagination and sorting by column name in . Pagination is working fine but search by column name is not working as per expected.
Here is my code :

index.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";
        }
        ?>

//Column name with link for sorting records

        <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>";
    }
    ?> 

//Pagination code

    <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>

Can anyone tell me what I am missing…. 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:46:58+00:00Added an answer on June 17, 2026 at 6:46 am
        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);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a listings page where each listing has its own div, the
I have a very AJAX-ish listing webpage created using Codeigniter where I want registered
I have created a custom post type named People. I have created a page
I have created a three page web page and I'm using an external css
I have an index page for listing products. From this page I would like
I have a scenario where I have a nested listing page which needs to
I need to reorganize the product listing category page. I have a date_field attribute
I have created a php site, and previously it was listing only products with
I have done pagination with CodeIgniter and it is listing Results from my database
I am working on a customisation for CRM 2011. I have created a custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.