0

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

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

因此,当我在我的 php 表单中按下基础按钮(第二张图片)时,只有他们的舞台是基础的记录才会显示在列表中(连同他们的姓名、联系电话、电子邮件和学生证)有什么方法可以让我可以这样做

4

2 回答 2

0

你在寻找这样的东西吗?

<?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();
  }
于 2013-06-09T15:17:32.543 回答
0
<?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>";
    } 
?>
于 2013-06-11T01:44:46.767 回答