如何在按钮单击中获取行ID? [英] How to get row ID in button click?

查看:132
本文介绍了如何在按钮单击中获取行ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,该表中填充了数据库中的记录.单击查看按钮时,我想做的是能够获取行的ID,以便可以调用用户的其他信息,但是我不确定如何执行此操作.这是我填表的方式.

I have a table that I fill with records from the database. What I want to do when the view button is clicked is to be able to get the ID of the row so that I can call on the other information of the user but I'm not quite sure how to do it. Here's how I filled the table.

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

推荐答案

您可以为每个按钮制作一些小表格,但我更喜欢将其设置为类似于按钮的超链接:

You could make little forms for each button but I prefer hyperlinks that I then style to look like buttons:

<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做更多的事情,但这应该给您正确的想法.

You can do more with the CSS but that should give you the right idea.

这篇关于如何在按钮单击中获取行ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆