通过复选框选择数据单击下一步并取消选择所选行 [英] Select Data by check box click next and unselect the selected row

查看:54
本文介绍了通过复选框选择数据单击下一步并取消选择所选行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的大学项目创建一个 crf 表单.我创建了课程表,我从课程中选择了一些数据,但学生单击已完成的课程,然后单击.然后下一页显示相同的数据库表,但不是那些课程,学生已选择.和然后学生可以子集应用课程.但是当我选择一些课程并单击下一步时,它会显示课程表中的前一行.但我希望在单击时不选择选定的课程行.导致完成的课程不想选择申请课程.

  1. 我想在应用时从数据库中选择一些行,它显示除所选行之外的所有行

我在问题行中添加了相同的行..

 <头><标题>CRF表格<link rel="stylesheet" href="CSS/admin_style.css" ><身体><div id="标题"><a href="index.php"><h1>欢迎使用 CRF 表格</a>

<form action="selection.php" method="POST" enctype="multipart/form-data" ><div id=""><table width="1000" border="5" align="center"><tr><td colspan="8" align="center" bgcolor="yellow"><h1>选择您已完成的课程</td></tr><tr bgcolor="橙色"><th>选择:</th><th>课程编号:</th><th>课程名称:</th><th>课程学分:</th><th>课程状态:</th><th>删除帖子:</th><th>编辑帖子:</th></tr><?phpinclude("includes/connect.php");$query="select * from course";$run=mysql_query($query);while($row=mysql_fetch_array($run)){$id=$row['id'];$course_id=$row['course_id'];$course_title=$row['course_title'];$course_credits=$row['course_credits'];$course_status=$row['course_status'];?><tr align="center" bgcolor="pink"><td><input type="checkbox" name="complete[]" value="<?php echo $id; ?>"/></td><td><?php echo $course_id;?></td><td><?php echo $course_title;?></td><td><?php echo $course_credits;?></td><td><?php echo $course_status;?></td><td><a href="delete.php?del=<?php echo $post_id ?>">删除</a></td><td><a href="Edit.php?edit=<?php echo $post_id ?>">编辑</a></td></tr><?php } ?><tr><td align="center" colspan="7"><input type="submit" name="sub" value="NEXT"></td></tr></表单>

</html>

这是 selec.php

<头><标题>CRF表格<link rel="stylesheet" href="CSS/admin_style.css" ><身体><div id="标题"><a href="index.php"><h1>欢迎使用 CRF 表格</a>

<div id=""><table width="1000" border="5" align="center"><tr><td colspan="8" align="center" bgcolor="yellow"><h1>选择您已完成的课程</td></tr><tr bgcolor="橙色"><th>选择:</th><th>课程编号:</th><th>课程名称:</th><th>课程学分:</th><th>课程状态:</th><th>删除帖子:</th><th>编辑帖子:</th></tr><?phpinclude("includes/connect.php");$check=$_POST['完成'];foreach($check as $ch){$select=" id!='".$ch."' and ";//这里是问题所在}$query="select * from course$select id!='0'";$run=mysql_query($query);while($row=mysql_fetch_array($run)){$id=$row['id'];$course_id=$row['course_id'];$course_title=$row['course_title'];$course_credits=$row['course_credits'];$course_status=$row['course_status'];?><tr align="center" bgcolor="pink"><td><input type="checkbox" name="completed"/></input></td><td><?php echo $course_id;?></td><td><?php echo $course_title;?></td><td><?php echo $course_credits;?></td><td><?php echo $course_status;?></td><td><a href="delete.php?del=<?php echo $post_id ?>">Delete</a></td><td><a href="Edit.php?edit=<?php echo $post_id ?>">Edit</a></td></tr><?php } ?>

</html>

解决方案

我认为您是说一旦选择了课程,它就不应该显示在学生可以查看另一页的下一页上课程?

如果是这样,那么您可以在不希望显示学生已完成课程的下一页使用以下 sql 查询.

SELECT * FROM course WHERE id != $course_id

如果我错了,请告诉我.我没有评论,因为我的声誉很低,而且 stackoverflow 不允许我这样做.

这是您的完整代码.

<块引用>

您选择的 php 文件:

//假设您使用学生的用户名或电子邮件 ID 登录,如果是,则将他们的用户名存储在登录的会话中.<?php$user = $_SESSION['用户名'];include("includes/connect.php");if (isset($_POST['submit'])){$course_id= $_POST['course_id'];$course_title= $_POST['course_title'];$course_credits= $_POST['course_credits'];$course_status= $_POST['course_status'];$query="SELECT course.id,course.title,course.credits,course.status FROM course WHERE course.username = $user";$run=mysqli_query($conn,$query);while($row=mysqli_fetch_array($run)){$course_id= $_SESSION['course_id'] = $row['course_id'];$course_title=$row['course_title'];$course_credits=$row['course_credits'];$course_status=$row['course_status'];}?>

<块引用>

现在在您的下一个 php 文件中:

$already_selected_course = $_SESSION['course_id'];现在查询应该看起来像.$query = "SELECT course.id,course.title,course.credits,course.status FROM course WHERE course.id != $already_selected_course";

就是这样.注:此方案可能有括号等错误,但逻辑清晰.

要获得更好的知识,请在此处查看我的 MySQL 完整视频系列

I want to create a crf form for my university project . i created course table i select some data from course but where student click the completed course and next click .then next page show same data base table but not those courses, student already selected.and then student can subset for applied courses. But when i select some course and click next, But it show the previous row in course table. but i want selected course row not select when i click . cause completed course not want to select for applying course.

  1. I want to select some row from a database when aply it show the same databases all row except the selected row

i add the same line in the problem line..

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html>
  <head>
        <title>
         CRF Form
         </title>
    <link rel="stylesheet" href="CSS/admin_style.css" >
   </head>  
<body>
    <div id="header">
    <a href="index.php">
        <h1>
            Welcome to the CRF Form
        </h1>
    </a>
    </div>
    <form action="selection.php" method="POST" enctype="multipart/form-data" >
    <div id="">
        <table width="1000" border="5" align="center">
        <tr>
            <td colspan="8" align="center" bgcolor="yellow">
            <h1>
            Slect your completed course
            </h1>
            </td>
        </tr>
        <tr bgcolor="orange">
            <th>
                selection:
            </th>
            <th>
                Course id:
            </th>
            <th>
                Course title:
            </th>
            <th>
                Course credits:
            </th>
            <th>
                Course statust:
            </th>
            <th>
                Delete Post:
            </th>
            <th>
                Edit Post:
            </th>

        </tr>

    <?php 
    include("includes/connect.php");

    $query="select * from course";

    $run=mysql_query($query);

    while($row=mysql_fetch_array($run)){
    $id=$row['id'];
    $course_id=$row['course_id'];
    $course_title=$row['course_title'];
    $course_credits=$row['course_credits'];
    $course_status=$row['course_status'];

    ?>


        <tr align="center" bgcolor="pink">
            <td>
            <input type="checkbox" name="complete[]" value="<?php echo $id; ?>" />

            </td>
            <td>
            <?php echo $course_id; ?>
            </td>
            <td>
            <?php echo $course_title; ?>
            </td>
            <td>
            <?php echo $course_credits; ?>
            </td>
            <td>
            <?php echo $course_status; ?>
            </td>
            <td>
            <a href="delete.php?del=<?php echo $post_id ?>">
            Delete
            </a>
            </td>
            <td>
            <a href="Edit.php?edit=<?php echo $post_id ?>">
            Edit
            </a>
            </td>
        </tr>


        <?php } ?>


        <tr>
        <td align="center" colspan="7">
        <input type="submit" name="sub" value="NEXT">
        </td>
        </tr>

        </table>

        </form>
    </div>
</body>
</html>

this is the selec.php

<html>
<head>
    <title>
    CRF Form
    </title>
    <link rel="stylesheet" href="CSS/admin_style.css" >
</head> 
<body>
    <div id="header">
    <a href="index.php">
        <h1>
            Welcome to the CRF Form
        </h1>
    </a>
    </div>

    <div id="">
        <table width="1000" border="5" align="center">
        <tr>
            <td colspan="8" align="center" bgcolor="yellow">
            <h1>
            Slect your completed course
            </h1>
            </td>
        </tr>
        <tr bgcolor="orange">
            <th>selection:</th>
            <th>Course id:</th>
            <th>Course title:</th>
            <th>Course credits:</th>
            <th>Course statust:</th>
            <th>Delete Post:</th>
            <th>Edit Post:</th>

        </tr>

    <?php 
    include("includes/connect.php");

    $check=$_POST['complete'];
    foreach($check as $ch){
    $select= " id!='".$ch."' and ";//here is the problem
    }


    $query="select * from course
    where $select id!='0'";

    $run=mysql_query($query);

    while($row=mysql_fetch_array($run)){
    $id=$row['id'];
    $course_id=$row['course_id'];
    $course_title=$row['course_title'];
    $course_credits=$row['course_credits'];
    $course_status=$row['course_status'];

    ?>


        <tr align="center" bgcolor="pink">
            <td>
            <input type="checkbox" name="completed" /></input>

            </td>
            <td><?php echo $course_id; ?></td>
            <td><?php echo $course_title; ?></td>
            <td><?php echo $course_credits; ?></td>
            <td><?php echo $course_status; ?></td>
            <td><a href="delete.php?del=<?php echo $post_id ?>">Delete</a></td>
            <td><a href="Edit.php?edit=<?php echo $post_id ?>">Edit</a></td>
        </tr>

        <?php  } ?>



        </table>
    </div>
</body>
</html>

解决方案

I think that you're saying the once the course is selected it shouldn't be displayed on the next page where the student can have a look on the other courses?

If is so then you can use following sql query on the next page where you don't want to display the student's completed course.

SELECT * FROM course WHERE id != $course_id

Let me know if I'm wrong. I didn't comment out as my reputations were low and stackoverflow didn't allow me to.

[EDITED]

This is your complete code.

Your select php file:

//assuming that you are logging in the students with their username or email id, if so then store their username in a session where logging in.
<?php 
    $user = $_SESSION['username'];
    include("includes/connect.php");

    if (isset($_POST['submit'])){

    $course_id= $_POST['course_id'];
    $course_title= $_POST['course_title'];
    $course_credits= $_POST['course_credits'];
    $course_status= $_POST['course_status'];

    $query="SELECT course.id,course.title,course.credits,course.status FROM course WHERE course.username = $user";

    $run=mysqli_query($conn,$query);

    while($row=mysqli_fetch_array($run)){
    $course_id= $_SESSION['course_id'] = $row['course_id'];
    $course_title=$row['course_title'];
    $course_credits=$row['course_credits'];
    $course_status=$row['course_status'];
}
    ?>

Now in your next php file :

$already_selected_course = $_SESSION['course_id'];

Now the query should look like.

$query = "SELECT course.id,course.title,course.credits,course.status FROM course WHERE course.id != $already_selected_course";

This is it. Note: This solution might contain some errors of brackets etc but the logic is clear.

For better knowledge have a look at my MySQL Complete Video Series here!

这篇关于通过复选框选择数据单击下一步并取消选择所选行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆