下拉列表无法排序

时间:2017-12-07 02:53:57

标签: php html mysql datatable

我在排序下拉菜单时遇到问题。

到目前为止,我的数据表可以对ID,名称,位置和应用日期进行排序,如图所示。 但是我的数据表无法对类别进行排序。我该如何对类别进行排序?感谢您的帮助。

以下是我用来显示数据表中数据的代码。

Here is a picture of my user interface 很抱歉使用链接,我是新手,不允许使用图片。

<table class="table isSearch table-bordered table-striped"  id="table" cellspacing="0">                     
    <thead>          
        <tr class="table-heads ">
            <th>ID</th>
            <th>Name</th> <!-- Table Header -->
            <th>Position</th>
            <th>Application Date</th>
            <th>Category</th>
            <th>Arrange Interview</th>
                <th>Online Interview</th></tr>

        </thead>

        <tbody>
              <?php
                include"../database.php";
              $query="SELECT user.name, job_application.created_at, 
              job.job_name, job_application_id, status_id, email, skypeid 
              FROM user, job_application, job 
              WHERE user.user_id = job_application.user_id 
              AND job.job_id = job_application.job_id 
              ORDER BY STATUS_ID ASC"; 
              $result=mysqli_query ($connect,$query);    

              while($data = mysqli_fetch_array($result))
                  { 
                  echo 
                "<tr><form action='update_status.php?id=".$data['job_application_id']."' method='post'>";
                echo"<td>".$data['job_application_id']."</td>";
                echo"<td>".$data['name']."</td>";
                echo"<td>".$data['job_name']."</td>";
                echo"<td>".$data['created_at']."</td>"; 
                echo"<td>
                <select name='status'>
                    <option name='status' value='1'";?><?php if ($data['status_id']=='1') {echo " selected";}echo "> Waiting </option>
                    <option name='status' value='2'";?><?php if ($data['status_id']=='2') {echo " selected";}echo "> Rejected </option>
                    <option name='status' value='3'";?><?php if ($data['status_id']=='3') {echo " selected";}echo "> Interviewed </option>
                    <option name='status' value='4'";?><?php if ($data['status_id']=='4') {echo " selected";}echo "> Hired </option>
                </select>
                    <br>
                    <input type='submit' name='submit' value='Save'>
                    </form>
                </td>";                
                echo"<td>
               <center><a href='email.php?email=".$data['email']."&id=".$data['job_application_id']." 'target='_blank' style='border-radius:30px' class='btn btn-secondary btn-sm'>E-Mail</a><center>
                </td>";
                echo"<td><center><a href='skype:".$data['skypeid']."?call' style='border-radius:30px' class='btn btn-primary btn-sm'><img src='assets/images/skype.png' width='25 height='13'>Call</a><center></td>";
                echo"</tr>"; 
                  }
                  ?>
            </tbody>
          </table>

1 个答案:

答案 0 :(得分:0)

您需要做的是在javascript中创建一个本地数组

          var categories = [];

并将数据从数据库推送到此变量

          categories.push({}) // you can push the object or the string

然后使用自定义逻辑https://www.w3schools.com/jsref/jsref_sort.asp定义sort函数。

           function sortTheCategory();

现在根据标题列发生的事件调用此函数。