0

データベースからのレコードを入力するテーブルがあります。ビューボタンをクリックしたときにやりたいことは、行のIDを取得して、ユーザーの他の情報を呼び出すことができるようにすることですが、その方法がよくわかりません。これが私がテーブルを埋めた方法です。

 <table border="1" cellpadding="5" cellspacing="2" width="600">
<tr>
    <th>ID</th>
    <th>Username</th>
    <th>Email</th>
    <th>Telephone</th>
    <th>Date Registered</th>
    <th>Member Details</th>
</tr>

 <?php
require('db_connection.php');
$query="SELECT ID,Username,Email,Telephone,RegisterDate FROM Members";
$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
    echo "</td><td>";
    echo $row['ID'];
    echo "</td><td>";
    echo $row['Username'];
    echo "</td><td>";
    echo $row['Email'];
    echo "</td><td>";
    echo $row['Telephone'];
    echo "</td><td>";
    echo $row['RegisterDate'];
    echo "</td><td>";
    print '<center><input name="ViewBtn" type="submit" value="View" /></center>';
    echo "</td></tr>";
}
?>

画像

4

3 に答える 3

2

ボタンごとに小さなフォームを作成することもできますが、ボタンのようにスタイルを設定するハイパーリンクを好みます。

<style type="text/css">
  .buttonize {
    text-decoration: none;
    border: 1px solid #ccc;
    background-color: #efefef;
    padding: 10px 15px;
    -moz-border-radius: 11px;
    -webkit-border-radius: 11px;
    border-radius: 11px;
    text-shadow: 0 1px 0 #FFFFFF;
  }
</style>

<table border="1" cellpadding="5" cellspacing="2" width="600">
<tr>
    <th>ID</th>
    <th>Username</th>
    <th>Email</th>
    <th>Telephone</th>
    <th>Date Registered</th>
    <th>Member Details</th>
</tr>

 <?php
require('db_connection.php');
$query="SELECT ID,Username,Email,Telephone,RegisterDate FROM Members";
$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
    echo "</td><td>";
    echo $row['ID'];
    echo "</td><td>";
    echo $row['Username'];
    echo "</td><td>";
    echo $row['Email'];
    echo "</td><td>";
    echo $row['Telephone'];
    echo "</td><td>";
    echo $row['RegisterDate'];
    echo "</td><td>";
    print '<center><a href="view.php?id='.$row['ID'].'" class="buttonize">View</a></center>';
    echo "</td></tr>";
}
?>

CSS を使用してさらに多くのことができますが、正しいアイデアが得られるはずです。

于 2012-05-10T01:48:44.980 に答える
2

ボタン HTML を介して行 ID を送信します

<button type="submit"  id="" title="" onClick="high('a<?php echo $i;?>')"  >

JS:

js を使用して ID を取得する

function high(id)
{
        alert(id);
}
于 2015-03-13T10:32:01.587 に答える
1

次のように、非表示の入力要素を使用できます。

"<input type=hidden id='rowid' value=".row['ID'].">";e

于 2012-05-10T01:54:04.370 に答える