我正在处理联系人应用程序,我必须使用下面代码中显示的联系人按钮来查看联系人


i am working on contact application and i have to view contact using contact button shown in below code

我的代码如下:

while($row = mysqli_fetch_array($result))  {
  echo "<tr><td>"."<input type='checkbox' name='checkbox[]' value=".$row['id'].">"."</td>"; echo "<td>" . $row['firstname']. "</td>";
  echo "<td>" . $row['lastname']. "</td>";
  echo "<td>" . $row['email']. "</td>";
  echo "<td>". "</td>";  echo "<td>"."<input type='button' name='view' id='view' value='View'  />"."</td>";     echo "</tr>";
echo "</tbody>"; }
echo "</table>";  }   ?>

根据您的问题,我想您喜欢获取某个记录的详细信息。我在这里放了一些代码。使用按钮而不是的最简单方法是使用引导程序。

db.php

<?php
class Database
{
    private static $dbName = 'Customer' ;
    private static $dbHost = 'localhost' ;
    private static $dbUsername = 'root';
    private static $dbUserPassword = '';
    private static $cont  = null;
    public function __construct() {
        die('Init function is not allowed');
    }
    public static function connect()
    {
       // One connection through whole application
       if ( null == self::$cont )
       {     
        try
        {
          self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword); 
        }
        catch(PDOException $e)
        {
          die($e->getMessage()); 
        }
       }
       return self::$cont;
    }
    public static function disconnect()
    {
        self::$cont = null;
    }
}
?>

dummy.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link   href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
            <div class="row">
                <h3>PHP CRUD Grid</h3>
            </div>
            <div class="row">
                <table class="table table-striped table-bordered">
                  <thead>
                    <tr>
                      <th>Name</th>
                      <th>Email Address</th>
                      <th>Mobile Number</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
                   include 'db.php';
                   $pdo = Database::connect();
                   $sql = 'SELECT * FROM contacts ORDER BY id DESC';
                   foreach ($pdo->query($sql) as $row) {
                            echo '<tr>';
                            echo '<td><a href="detail.php?id='.$row["id"].'">'. $row['name'] . '</a></td>';
                            echo '<td>'. $row['email'] . '</td>';
                            echo '<td>'. $row['mobile'] . '</td>';
                            echo '</tr>';
                   }
                   Database::disconnect();
                  ?>
                  </tbody>
            </table>
        </div>
    </div> <!-- /container -->
  </body>
</html>

detail.php

<?php 
  $id = $_GET['id'];
?>
<?php
 include 'db.php';
 $pdo = Database::connect();
 $sql = 'SELECT * FROM contacts WHERE id='.$id;
 foreach ($pdo->query($sql) as $row) {
          echo "<div>";
          echo "<p> ".$row['name']." </p>";
          echo "<p> ".$row['email']." </p>";
          echo "<p> ".$row['mobile']." </p>";
          echo "</div>";
 }
 Database::disconnect();
?>

假设我的数据库名称为"Customer",表名称为"contacts"db.php是数据库连接类。如果您查看dummy.php,您会发现您已经实现了记录列表。因此,为了回答您的问题,我在name字段中放置了一个标记,该标记重定向到参数为id的detail.php。在那里你可以获取联系人的详细信息。。希望它能满足您的需求