0

我有一个简历数据库,你可以看到下面的字段,它们非常标准。检索是通过将信息发送到 SQL 数据库的简单表单来完成的。

我对我的简单系统很满意,直到我的收件箱里涌入了超过 500 名申请者。我以前的系统只允许我一个一个地查看申请人,这将永远需要......

我想要实现的是一个简单的后端页面,类似于表格视图的 phpmyadmin。(不,我不想只使用 phpmyadmin,因为我想将简历筛选任务交给其他员工)

基本上,这个概念是像 Excel 一样显示表格,允许通过单击标题、分页 [每页 20 行] 和删除行的复选框进行排序。

我可以寻求帮助,因为我已经付出了很多努力来解决这个问题;)

到目前为止,我得到的是:

排序没有问题,单击其中一个标题会向地址栏吐出 localhost/mena/new3.php?sort=fname 并解析正确的 Sql 查询并对页面进行排序。

分页到目前为止不起作用。该页面显示所有 815 名候选人。它提供了编号为 1-42 的链接,单击该链接会导致地址栏更改为 localhost/new3.php?page=2 但 0 更改。

同样对于我的生活,我看不到如何将 php delete 包含在其中。

9 yo 伪代码的想法是:

//Input the rows from SQL
While($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td> $checkbox1
  if checkbox1=true then mysqli_query($con,"DELETE FROM cv WHERE .$row[].");
  echo "<td>" . $row['title'] . 

到目前为止我的代码:

<?php
$con=mysqli_connect("localhost","root","","test_db-jil");
// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Pagination  
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * 20; 

// Sort, from headers.
if(isset($_REQUEST['sort'])){
    if($_GET['sort'] == "title"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY title");
    }
    elseif($_GET['sort'] == "fname"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY fname");
    }
    elseif($_GET['sort'] == "lname"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY lname");
    }
    elseif($_GET['sort'] == "gender"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY gender");
    }
    elseif($_GET['sort'] == "dob"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY dob");
    }
    elseif($_GET['sort'] == "nationality"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY nationality");
    }
    elseif($_GET['sort'] == "language"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY language");
    }
    elseif($_GET['sort'] == "phone"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY phone");
    }
    elseif($_GET['sort'] == "email"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY email");
    }
    elseif($_GET['sort'] == "uni"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY uni");
    }
    elseif($_GET['sort'] == "prog"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY prog");
    }
    elseif($_GET['sort'] == "graddate"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY graddate");
    }
    elseif($_GET['sort'] == "startdate"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY startdate");
    }
    elseif($_GET['sort'] == "grad"){
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY grad");
    }   
    else{
    $result = mysqli_query($con,"SELECT * FROM cv ORDER BY fname");
    }
}
else{ // Default if no parameters passed
    $result = mysqli_query($con,"SELECT * FROM cv");
    }


//Table of Content  
echo "<table border='1'>
<tr>
<th><a href=new3.php?sort=title>Title</a></th>

<th><a href=new3.php?sort=fname>First Name</a></th>

<th><a href=new3.php?sort=lname>Last Name</a></th>

<th><a href=new3.php?sort=gender>Gender</a></th>

<th><a href=new3.php?sort=dob>Date Of Birth</a></th>

<th><a href=new3.php?sort=nationality>Nationality</a></th>

<th><a href=new3.php?sort=language>Language</a></th>

<th><a href=new3.php?sort=phone>Phone No</a></th>

<th><a href=new3.php?sort=email>Email</a></th>

<th><a href=new3.php?sort=uni>University</a></th>

<th><a href=new3.php?sort=prog>Program</a></th>

<th><a href=new3.php?sort=graddate>Graduated</a></th>

<th><a href=new3.php?sort=startdate>Start Date</a></th>

<th><a href=new3.php?sort=grad>Applying for</a></th>

<th>CV File</th>

</tr>";

//Input the rows from SQL
While($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['title'] . "</td>";
  echo "<td>" . $row['fname'] . "</td>";
  echo "<td>" . $row['lname'] . "</td>";
  echo "<td>" . $row['gender'] . "</td>";
  echo "<td>" . $row['dob'] . "</td>";
  echo "<td>" . $row['nationality'] . "</td>";
  echo "<td>" . $row['language'] . "</td>";
  echo "<td>" . $row['phone'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "<td>" . $row['uni'] . "</td>";
  echo "<td>" . $row['prog'] . "</td>";
  echo "<td>" . $row['graddate'] . "</td>";
  echo "<td>" . $row['startdate'] . "</td>";
  echo "<td>" . $row['grad'] . "</td>";
  echo "<td><a href=" . $row['cvfilename'] .">" . $row['cvfilename'] ."</a></td>";


  echo "</tr>";
  }
echo "</table>";

//Get total count of rows then ceil divide by 20 as pages
$sql = "SELECT COUNT(*) as 'num' FROM cv";
$total_pages = $con->query($sql) or die(mysqli_error($connection)); 
$row = $total_pages->fetch_assoc();
$total_pages  = ceil($row['num'] / 20);

for ($i=1; $i<=$total_pages; $i++) { 
            //Can I ?page= and ?sort= ??????
            echo "<a href='new3.php?page=".$i."'>".$i."</a> "; 
};

mysqli_close($con);
?>

回顾一下,请帮我修复分页,让它与排序一起工作,最后为每一行添加一个删除复选框。:)

4

1 回答 1

1

你知道你可以优化整个“else if”语句块,只需分配

$_GET 到一个变量: $type = $_GET;

然后在你的 mysqli 中使用它: $result = mysqli_query($con, "SELECT * FROM cv ORDER BY $type");

要限制结果,请使用 LIMIT: $result = mysqli_query($con, "SELECT * FROM cv ORDER BY $type LIMIT 20, $page");

20 = 返回多少 $page = 你希望结果从哪里开始

于 2013-06-03T16:09:47.317 回答