从php链接按钮获取链接ID

时间:2016-08-02 06:38:34

标签: php button hyperlink

嗨,这是我的php文件的一部分。

include_once 'dbconnect.php';
$query  = "SELECT * FROM promoter";
$result = mysql_query($query);
echo "<table border=\"2\">\n"; 
echo "   <tr>\n"; 
echo "      <th>Id</th>\n"; 
echo "      <th>User Id</th>\n"; 
echo "      <th>Full Name</th>\n"; 
echo "      <th>Qualification</th>\n";
echo "      <th>Locality</th>\n";
echo "      <th>Description</th>\n";
echo "      <th>Language</th>\n";
echo "      <th>Bank Details</th>\n";
echo "      <th>Change</th>\n";


echo "    </tr>\n";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{   
print "<tr> <td>";
    echo $row['id']; 
    print "</td> <td>";
    echo $row['user_id']; 
    print "</td> <td>";
    echo $row['full_name']; 
    print "</td> <td>";
    echo $row['qualification'];
    print "</td> <td>";
    echo $row['locality'];
    print "</td> <td>";
    echo $row['description'];
    print "</td> <td>";
    echo $row['language'];
    print "</td> <td>";
    echo $row['bank_details'];
    print "</td> <td>";
     //echo '<a href="update.php" >Modi</a>';
    echo '<a href="update.php" id= "<?php echo $row['id'];?>">Modify</a>';
    print "</td> </tr>";

}



echo " </table>\n";
include 'closedb.php';

我希望在点击按钮链接时获取表格行的行ID。我怎么能得到它?表格的每一行都有一个链接,因此当点击链接时,它应该将行['id']作为id值,因此每个链接都有其行id的id值。

3 个答案:

答案 0 :(得分:0)

试试这个,

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{   
    print "<tr> <td>";
    echo $row['id']; 
    print "</td> <td>";
    echo $row['user_id']; 
    print "</td> <td>";
    echo $row['full_name']; 
    print "</td> <td>";
    echo $row['qualification'];
    print "</td> <td>";
    echo $row['locality'];
    print "</td> <td>";
    echo $row['description'];
    print "</td> <td>";
    echo $row['language'];
    print "</td> <td>";
    echo $row['bank_details'];
    print "</td> <td>";
     //echo '<a href="update.php" >Modi</a>';
    echo '<a href="update.php?id= "'.$row['id'].'">Modify</a>';
    print "</td> </tr>";

}

答案 1 :(得分:0)

试试这个,

(in your php file)
echo '<a href="update.php" id= ".$row['id']." onclick="getId(this)">Modify</a>';

<script>
function getId(link){
    alert(link.id);
}
</script>

答案 2 :(得分:0)

PHP可以使用多种类型的requests。最常见的两个是POSTGET请求。

GET请求是您在正常点击链接时对服务器执行的请求。

实施例

<a href="index.php?id=1">Click me</a>

<?php if (isset($_GET['id'])): ?>
    The requested id is <?= $_GET['id']; ?>
<?php endif; ?>

在上面的示例中,我们使用index.php参数GET请求id。 PHP将这些参数存储在超全局$_GET

在你的情况下:

while (...) {
    echo "<a href='modify.php?id='".$row['id']."'>Modify</a>";
}