How to show chosen data row from database in other page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Noss
Forum Newbie
Posts: 1
Joined: Thu Jul 30, 2009 3:29 pm

How to show chosen data row from database in other page?

Post by Noss »

Hello to everyone,

Could you help me or suggest how to do it: my idea is to show data on other page after clicking the button. Till now i have done is printing a table which has data taken from database. Every row in the end has a button, then this button is pressed i want to take all information in this row and show it in other page. Example: if i choose row number 3, all data from that row has to be printed in other page. Can you suggest or show how to do it?

This is my code:

Code: Select all

<? session_start();
include ("db.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untiteled</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table width="900" border="0" cellpadding="0" cellspacing="0" class="rem">
  <tr>
    <td>
    <?php 
 
if ($_SESSION['username'])
    echo "Hello, ".$_SESSION['username']."!<br><a href='logout'>Logout</a>";
else
    echo "You have to <a href='index.php'>log in</a>";
 
$result = mysql_query("select * from user");
 
$myrow = mysql_fetch_array ($result);
do 
{
    printf("<table width='900' border='0' cellpadding='0' cellspacing='0' class='rem'>
  <tr>
    <td>
    
</td>
  </tr>
  <tr>
    <td>
    <table class='tam' width='900' border='0' cellspacing='0' cellpadding='0'>
      <tr>
        <td>Number</td>
        <td>Name</td>
        <td>Last Name</td>
        <td>Email</td>
        
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width='900' border='0' cellspacing='0' cellpadding='0'>
      <tr>
        <td width='92'>%s</td>
        <td width='342'>%s</td>
        <td width='157'>%s</td>
        <td width='179'>%s</td>
        
        <td><input type='submit' value='Send' action='' ></td>
      </tr>
    </table></td>", $myrow['id'],$myrow['name'],$myrow['lname'],$myrow['mail']);
    }
    while ($myrow = mysql_fetch_array ($result));
    ?>
  </tr>
</table>
</body>
</html>
 
 
Thanks for help
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: How to show chosen data row from database in other page?

Post by jackpf »

If you put echo '<a href="anotherpage.php?id='.$myrow['ID'].'">Click</a>'; then on anotherpage.php you can use $_GET['id'] for reference as to what record to fetch data for.
Post Reply