我正在处理联系人申请,我必须使用以下代码中显示的联系按钮查看联系人

时间:2015-02-08 04:43:52

标签: php

我的代码如下:

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>";  }   ?>

1 个答案:

答案 0 :(得分:-1)

根据你的问题,我想你想要获取某个记录的细节。我在这里放了一些代码。使用按钮而不是 a 的最简单方法是使用bootstrap。

<强> 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();
?>

让我们假设我拥有数据库名称&#34;客户&#34;和表名&#34;联系人&#34; 。 db.php 是数据库连接类。如果你看一下 dummy.php ,你会发现你已经达到了记录列表。因此,为了回答您的问题,我在名称字段中添加 标记,并使用参数id重定向到 detail.php 。在那里你可以获取联系方式..希望它可以满足你的需求