繁体   English   中英

从数据库表中过滤记录以进行查看和更新

[英]Filtering records from database table to be view and update

我目前正在尝试从数据库中提取记录,并将其显示在我的php表单上,以供用户更新。 在我的数据库表中,有一个名为stage的列。 在阶段之下,有基础,中间和先进。 这是一个例子:

有效的XHTML http://img259.imageshack.us/img259/2461/databasei.png 有效的XHTML http://imageshack.us/photo/my-images/849/profileint.png/

因此,当我按php形式(第二张图片)中的按钮时,列表中将仅显示其阶段为基础的记录(以及他们的姓名,联系电话,电子邮件和学生证)。可以做到

您是否正在寻找这样的东西?

<?php
  $stage = $_GET['stage'];
  $sql = 'SELECT * FROM {$tablename} WHERE stage=:stage';

  $db = new PDO('mysql:host=localhost;dbname=yourdbname', $user, $pass);
  try {
    $statement = $db->prepare($sql);
    $statement->execute(array(':stage', db->quote($stage)));
    foreach($statement->fetchAll() as $row) {
      // Do things here.
    }
  } catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
  }
<?php
    include('connect-db2.php');

    // get results from database
    $result = mysql_query("SELECT * FROM players2 WHERE stage = 'foundation'") 
            or die(mysql_error());  

    echo "<table border='1' cellpadding='10'>";
    echo "<tr> <th>S/N</th> <th>Student_ID</th> <th>Name</th> <th>Contacts No.</th> <th>Email</th><th>Stage</th></tr>";

    while($row = mysql_fetch_array( $result )) {
        // echo out the contents of each row into a table
        echo "<tr>";
        echo '<td>' . $row['id'] . '</td>';
        echo '<td>' . $row['student_id'] . '</td>';
        echo '<td>' . $row['name'] . '</td>';
        echo '<td>' . $row['contact_no'] . '</td>';
        echo '<td>' . $row['email'] . '</td>';
        echo '<td>' . $row['stage'] . '</td>';
        echo '<td><a href="edit2.php?id=' . $row['id'] . '">Edit</a></td>';
        echo '<td><a href="delete2.php?id=' . $row['id'] . '">Delete</a></td>';
        echo "</tr>";
    } 
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM