2015-05-15 118 views
1

我想为我的大学项目创建一个crf表单。 我创建的课程表我选择课程,但其中一些数据学生点击完成课程和未来。然后点击下页显示相同的数据基础表,但没有这些课程,学生已经selected.and 然后学生可以子集应用型课程。 但是,当我选择一些课程,然后单击下一步,但它显示课程表中的前一行。但我想要选择的课程行不会选择当我点击。导致完成的课程不想选择应用课程。选择数据复选框单击下一步并取消选择所选行

  1. 我想从数据库中选择一些行时APLY它表现出同样的数据库中的所有行选定的行

我添加的问题行的同一行除了..

<!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> 

这是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> 
+0

你能澄清你的问题吗? –

+0

我想从数据库中选择一些行时,它显示相同的数据库所有行,除了选定的行 –

回答

2

我认为你说一次选择的课程不应该显示在下一页,学生可以看看其他课程?

如果是这样,那么你可以使用下面的下一个页面,你不希望显示在学生完成课程的SQL查询。

SELECT * FROM course WHERE id != $course_id 

让我知道如果我错了。我没有发表评论,因为我的声望很低,并且stackoverflow不允许我。

将帖子

这是你的完整代码。

你选择PHP文件:

//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']; 
} 
    ?> 

现在,在你的下一个php文件:

$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"; 

这是它。注意:该解决方案可能包含括号等错误,但逻辑清晰。

为了更好地了解看看我的MySQL Complete Video Series在这里!

+0

当我使用foreach($ check为$ ch){$ select =“id!='”。$ ch。“ '和“; //这是问题}它不工作,但如果我使用foreach {.........最后它重复更多的行...请告诉我如何忽略选定的行在表 –

+0

我已经用上面的完整代码编辑了我的答案。 –

+0

帮我给我意见.. 当我选择第i行从表中查看所选行.. 有没有什么办法,以显示所选行的联合国。 (我从复选框中选择数据) –

相关问题