master_yoda
master_yoda

Reputation: 483

combining table and a button in a php table

I am creating a table (in php) with the help of data from DB. I wanna add a button on the last row. I managed it. is it possible to make button press to load another php file? my code is as follows. any suggestions please.

part of my code where i am getting data from DB and displaying it on a table

echo '<table >';
echo '<tr><th>Namel</th>';
echo '<td >' . $row['Name']. '</td></tr>';

echo '<tr><th>ID</th>';
 echo '<td >' . $row['ID']. '</td></tr>';

echo "<tr><td colspan=2><input type='button' name='more' value='More Data' ></td></tr>";

echo "</table>";

how to make it clicking the button will take me to another page.

Upvotes: 0

Views: 107

Answers (2)

MasterDE
MasterDE

Reputation: 11

Try This:

echo "<tr><td colspan=2><input type='button' name='more' value='More Data' onClick='redirect()' ></td></tr>";

echo "</table>";

<script>
function redirect()
{
    window.location.href = "page to which it should redirect";//url of your page
}
</script>

Upvotes: 0

Roshni hegde
Roshni hegde

Reputation: 415

you can do it with javascript or jquery. Try to call javascript function on, onClick

Try the following

echo "<tr><td colspan=2><input type='button' name='more' value='More Data' onClick='redirect()' ></td></tr>";

echo "</table>";

<script>
function redirect()
{
    window.location.href = "page to which it should redirect";//url of your page
}
</script>

Upvotes: 1

Related Questions