排序和分页相结合,PHP与SQL
我有一个简历数据库,你可以看到下面的字段,它们非常标准。检索是通过将信息发送到SQL数据库的简单表单完成的 我对我的简单系统很满意,直到我的收件箱里挤满了500多名申请者。我以前的系统只允许我一个接一个地查看申请者,这将花费很长时间 我试图实现的是一个简单的后端页面,类似于表视图的phpmyadmin。(不,我不想只使用phpmyadmin,因为我想把简历筛选任务交给其他员工) 基本上,其概念是像excel一样显示表格,通过单击标题、分页[每页20行]和删除行的复选框来进行排序 我可以请求一些帮助,因为我已经花了很多精力试图解决这个问题;) 到目前为止,我得到的是: 排序工作没有问题,单击其中一个标题会将localhost/mena/new3.php?sort=fname输出到地址栏,解析正确的Sql查询并对页面进行排序 到目前为止,分页不起作用。该页面显示所有815名候选人。它提供了编号为1-42的链接,单击该链接会导致地址栏更改为localhost/new3.php?page=2,但更改为0 而且,就我的一生而言,我看不出如何将php删除包含在这个 9 yo伪代码的思想是:排序和分页相结合,PHP与SQL,php,sql,sorting,pagination,sql-delete,Php,Sql,Sorting,Pagination,Sql Delete,我有一个简历数据库,你可以看到下面的字段,它们非常标准。检索是通过将信息发送到SQL数据库的简单表单完成的 我对我的简单系统很满意,直到我的收件箱里挤满了500多名申请者。我以前的系统只允许我一个接一个地查看申请者,这将花费很长时间 我试图实现的是一个简单的后端页面,类似于表视图的phpmyadmin。(不,我不想只使用phpmyadmin,因为我想把简历筛选任务交给其他员工) 基本上,其概念是像excel一样显示表格,通过单击标题、分页[每页20行]和删除行的复选框来进行排序 我可以请求一些帮
//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'] .
//从SQL输入行
While($row=mysqli\u fetch\u数组($result))
{
回声“;
echo“$checkbox1
如果checkbox1=true,则mysqli_查询($con,“从cv中删除,$row[]);
回显“.$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);
?>
您知道只需分配
$\u获取一个变量:
$type=$\u GET
然后在mysqli中使用它:
$result=mysqli_查询($con,“按$type从简历订单中选择*)
要限制结果,请使用“限制”:
$result=mysqli_query($con,“按$type LIMIT 20$page从简历订单中选择*)
20=返回的数量
$page=您希望结果从哪里开始以减少zillion的混乱queries@your-然而现在我得到的常识是:(!)注意:未定义的索引:在第10行的C:\wamp\www\mena\index2.php中排序(“title”、“fname”、“lname”、“gender”、“dob”、“national”、“language”、“phone”、“email”、“uni”、“prog”、“graddate”startdate“,”grad“;//字段名$key=array_search($\u GET['sort'],$orders);//看看我们是否有这样一个名称$orderby=$orders[$key];//如果没有,第一个名称将自动设置。smart enuf:)$query=“按$orderby从简历顺序选择*”//值是安全的$result=mysqli_查询($con,$query);
第10行:'$key=array_search($\u GET['sort'],$orders);//看看我们是否有这样的名字'