Php 我正在处理联系人应用程序,我必须使用下面代码中显示的联系人按钮查看联系人
我的代码如下:Php 我正在处理联系人应用程序,我必须使用下面代码中显示的联系人按钮查看联系人,php,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[
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>"; } ?>
while($row=mysqli\u fetch\u数组($result)){
echo“.”;echo“$row['firstname']”;
回显“$row['lastname']”;
回显“$row['email']”;
回显“;回显“;回显“;
回声“;}
回声“;}?”>
根据你的问题,我猜你喜欢获取某个记录的细节。我在这里放了一些代码。使用按钮而不是a的最简单方法是使用引导
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;
}
}
?>
<!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>
<?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();
?>
dummy.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;
}
}
?>
<!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>
<?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();
?>
PHP积垢网格
名称
电子邮件地址
手机号码
detail.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;
}
}
?>
<!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>
<?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字段中放置了一个标记,该标记重定向到detail.php,参数为id。在那里你可以获取联系人的详细信息。。希望它能回答您的需求您的问题是什么?亲爱的rizier,我必须使用那边显示的view按钮获取代码中显示的特定行数据。帮助我。亲爱的桑尼,我必须使用那边显示的视图按钮获取代码中显示的特定行数据。帮助我。。