Reputation: 33
This is my code:
<?php
require("../EmptyPHP.php");
$query = "SELECT name, id FROM bank";
$result = mysql_query($query);
echo "<table style=width:40% border=1>";
echo "<tr>
<td width=50%>BANK NAME</td>
<td width=50%>BANK ID</td>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td >" . $row['name'] . "</td><td><a name=detail
href=viewDetails.php >" . $row['id'] . "</a></td></tr>";
}
echo "</table>";
?>
I get bank name and bank id as output, and I have to make when I click on particular bank id , that id has to be displayed in the next page i.e viewDetails.php .. so how to make that?
Upvotes: 0
Views: 547
Reputation: 578
try below code and make sure the location/path of view details page is right.Otherwise change your path.
<?php
require("../EmptyPHP.php");
$query = "SELECT name, id FROM banktb";
$result = mysql_query($query);
echo "<table style=width:40% border=1>";
echo "<tr>
<td width=50%>BANK NAME</td>
<td width=50%>BANK ID</td>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td >" . $row['name'] . "</td><td><a id='detail' name='detail' href='#'>" . $row['id'] . "</a></td></tr>";
}
echo "</table>";
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#detail").click(function(){
var getval=this.text;
this.href="viewDetails.php?"+getval;
});
});
</script>
now you will get id of particular click in viewdetail page..Now you have to get that particular id via get method and then fetch data of particular id using sql query.
Upvotes: 1
Reputation: 187
You have to use $_GET[];
in your case.
add this to your php code
viewDetails.php?bankname=$row['name']&bankid=$row['id']
and in your viewDetails.php
you have to get those variables using.
echo $name = $_GET['bankname'];
echo $id = $_GET['bankid'];
Hope it helps.
Upvotes: 0
Reputation: 8369
You can pass the id through url like:
"</td><td><a name=detail href=viewDetails.php?id=".$row['id'].">" . $row['id'] . "</a>
and can access it in the viewDetails.php page with
$id=$_GET['id'];
Upvotes: 0