0

谁能帮我整理一下?单击排序时没有任何错误尝试了 4 年前的代码不知道它是否仍然可用 sql.= 我认为不起作用或我的其他查询只是禁用它。这是我的 sql 命令,谢谢:D。帮助订购

              <table>
            <tr>
                <th>
                    <a href="?orderBy=date">Type:</a>
                </th>
                <th>
                    <a href="?orderBy=FirstName">Description:</a>
                </th>
                <th>
                    <a href="?orderBy=Lastname">Recorded Date:</a>
                </th>
                <th>
                    <a href="?orderBy=Date">Added Date:</a>
                </th>
            </tr>
        </table>


   <?php
    $sort=$_GET['orderBy'];
    $searchtext = '';


        if(isset($_GET['q']))


    $searchtext = mysql_real_escape_string($_GET['q']);

     if($searchtext) {
        $per_page =5;
        $pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' order by '$sort' desc ");
        $pages = ceil(mysql_result($pages_query,0) / $per_page);

        $page = (isset($_GET['page'])) ? (int)$_GET['page'] ;
        $start = ($page - 1) * $per_page;


        // And set the first page $first_page = "1";

        $num = mysql_num_rows($pages_query);
        $last_page = ($num / $per_page);
        $next_page = $page + 1;
        $last_page=$pages;
        $query=mysql_query("select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' order by '$sort' desc LIMIT $start,$per_page "); 

        $count=mysql_query("select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%'");  

        $numrows = mysql_num_rows($count);


            }

            else  {

               $per_page =5;
                      $pages_query = mysql_query("SELECT COUNT('PersonID') FROM persons ");
                      $pages = ceil(mysql_result($pages_query,0) / $per_page);

                      $page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
                      $start = ($page - 1) * $per_page;
                      $last_page=$pages;

        // And set the first page $first_page = "1";


        $query=mysql_query("select * from persons  order by '$sort' desc LIMIT $start,$per_page ");    $count=mysql_query("select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' order by '$sort'");   

        $numrows = mysql_num_rows($count);

排序不工作输出没有例子public_search.php?orderBy=FirstName

当我使用以下查询时更新:

select * from persons where firstname like '%$searchtext%' or lastname like '%$searchtext%' ORDER BY status DESC LIMIT $start,$per_page

它有效,所以我得出结论,它没有得到排序命令 sql 不会得到排序的值,试图回显它并工作。它输出排序但查询不会执行它

4

0 回答 0