Adding links to the table (hyperlink) in PHP
There are 2 ways: The easier way is to print
all data, but just not display it yet until someone clicks the link. For the
hyperlinked part.
Example: used a 'span' element which is styled like a hyperlink.
//place inside your head tag
<style>
.hyperlink-lookalike
{
text-decoration:underline;
color:blue;
cursor:pointer;
}
</style>
<script>
//javascript function to toggle extra animal info
function show_extra_info(id)
{
var tr = document.getElementById('extra_info_'+id);
if(tr.style.display=='none')
{
tr.style.display='table-row';
}
else{
tr.style.display='none';
}
}
</script>
//inside the loop
echo '<tr>';
echo '<td colspan='2'><span class="hyperlink-lookalike" onclick="show_extra_info(' . $row['id'] . ')">' . $row['name'] . '</span></td>';
echo '</tr>';
echo '<tr id="extra_info_' . $row['id'] . '" style="display:none;">';
echo '<td>' . $row['cost'] . '</td>';
echo '<td>' . $row['life'] . '</td>';
echo '</tr>';
The second way:- to use a hyperlink, and go to a detail view:
echo '<td><a href="http://www.example.com/animaldetailedinfo.php?id=' . $row['id'] . '">' . $row['name'] . '</a></td>';
display the text in the column as a static hyperlink by calling set_col_link() and passing the column name.
set_col_link() function:- Display the text in column as a static hyperlink.
EXAMPLE: - $dg -> set_col_link("productCode");
Example:
$dg = new C_DataGrid("select * from products", "productCode", "productcode");
$dg -> set_col_title("productCode", "Product Code");
$dg -> set_col_title("productName", "Product Name");
$dg -> set_col_title("productLine", "Product Line");
// display static Url
$dg -> set_col_link("productUrl");
$dg -> display();
==================================================
=============
0 Comments