簡體   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