我试图在php mysql中执行排序,但它正在整理整个数据,而不是选择一个

时间:2018-02-02 07:11:54

标签: php sorting mysqli

Hii我已经编写了一个用于在PHP中进行排序的查询,用于对表中的MySQL数据进行排序,其中它正在对所有数据进行排序,而不是对所选数据进行排序,例如:我搜索数据并将结果作为亚当,苹果,安东,所以我想对这些选定的数据进行排序并获得结果,如下面的亚当,安东,苹果,是我尝试对整个数据进行排序而不是选择

<?php

if(isset($_GET['search_btn'])){//here i'm clicking on search button to search the data
  $search=$_GET['search'];
  $result=GetWords(mysqli_escape_string($conn,$search));
}
/*if(isset($_GET['q'])){
      $id=$_GET['q'];
      $result=GetWordsById($id);
    }*/
    if(isset($_GET['sort'])){
      $sort=$_GET['sort'];
    }
    if(isset($_GET['sort'])){
      if($sort=="asc"){
        $result=SortContent();//Here SortContent is a function calling store procedure and it is sorting all the data
      }
      if($sort=="desc"){
        $result=SortContent2();
      }
    }


    else{
  $result=GetAdminWords();
}
  if(mysqli_num_rows($result)>0)
  ?>  
    <thead>
      <tr>

        <th>Word</th>
        <th>Meaning</th>
        <th>Synonym</th>
        <th>Antonym</th>

      </tr>
    </thead>
    <?php
    while($row=mysqli_fetch_array($result)){
    ?>
      <tbody>
        <tr>

          <td><a href="view.php?q=<?php echo $row['id'];?>"><?php echo $row['word'];?></a></td>
          <td><?php echo $row['meaning'];?></td>
          <td><?php echo $row['synonym'];?></td>
          <td><?php echo $row['antonym'];?></td>
         <td><a href="admin.php?id1=<?php echo $row['id'];?>"><i class="fa fa-edit"></i></a> <a onClick="javascript: return confirm('Please confirm deletion');" href="view.php?id=<?php echo $row['id'];?>"><i class="fa fa-trash"></i></a> </td>
        </tr>
      </tbody>
      <?php
  }?>


  </table>

下面是我的函数调用存储过程

function SortContent(){
    include("conn.php");
    $result=mysqli_query($conn,"CALL SortContent()");
    return $result;
}

我的商店程序看起来像

CREATE DEFINER=`root`@`localhost` PROCEDURE `SortContent`()
BEGIN
SELECT * from dictionarysearch ORDER BY word ASC;
END

我想知道如何更改此查询,以便仅对所选数据进行排序

0 个答案:

没有答案