Hi this is aa part of my php file.
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';
I want to get the row id of the of the table row when the button is link is clicked. How can i get that? There is a link for every row of the table , so when the link is clicked it should take the row ['id'] as the id value , so every link has the id value of its row id.
Try this,
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>";
}
Try this,
(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>
PHP can work with multiple types of requests
. The two most common ones are POST
and GET
requests.
The GET
request is the one that is being done to the server when you normally click a link.
<a href="index.php?id=1">Click me</a>
<?php if (isset($_GET['id'])): ?>
The requested id is <?= $_GET['id']; ?>
<?php endif; ?>
In the above example we are requesting index.php
with the GET
parameter id
. PHP stores these parameters in the superglobal $_GET
.
In your case:
while (...) {
echo "<a href='modify.php?id='".$row['id']."'>Modify</a>";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.